Compare commits
	
		
			No commits in common. "6525b6ead3458410321bfeba68c6070df11797c0" and "c9635a647ca78c18f5af7124e138fc167f4a277c" have entirely different histories.
		
	
	
		
			6525b6ead3
			...
			c9635a647c
		
	
		
| @ -66,9 +66,6 @@ func NewRouter() *gin.Engine { | |||||||
| 			acRoute.POST("approval", account.UserApproval) //实名审核
 | 			acRoute.POST("approval", account.UserApproval) //实名审核
 | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	{ |  | ||||||
| 		v1.POST("chart/forward/test", redirect.ForwardTest) |  | ||||||
| 	} |  | ||||||
| 	// 上传
 | 	// 上传
 | ||||||
| 	upData := privateGroup.Group("upload") | 	upData := privateGroup.Group("upload") | ||||||
| 	upData.Use(middleware.CheckLogin(service.AccountProvider)) | 	upData.Use(middleware.CheckLogin(service.AccountProvider)) | ||||||
|  | |||||||
| @ -5,7 +5,6 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"fonchain-fiee/pkg/service" | 	"fonchain-fiee/pkg/service" | ||||||
| 	"github.com/gin-gonic/gin" | 	"github.com/gin-gonic/gin" | ||||||
| 	"io" |  | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"time" | 	"time" | ||||||
| ) | ) | ||||||
| @ -33,48 +32,3 @@ func ToRedirectRealUrlAdnRand(c *gin.Context) { | |||||||
| 
 | 
 | ||||||
| 	c.Redirect(http.StatusMovedPermanently, realUrl+fmt.Sprintf("?time=%d", time.Now().Unix())) | 	c.Redirect(http.StatusMovedPermanently, realUrl+fmt.Sprintf("?time=%d", time.Now().Unix())) | ||||||
| } | } | ||||||
| func ForwardTest(c *gin.Context) { |  | ||||||
| 	// 1. 创建HTTP客户端(设置超时避免长时间等待)
 |  | ||||||
| 	client := &http.Client{ |  | ||||||
| 		Timeout: 10 * time.Second, |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 2. 构造请求
 |  | ||||||
| 	req, err := http.NewRequest("GET", "https://stockanalysis.com/chart/__data.json", nil) |  | ||||||
| 	if err != nil { |  | ||||||
| 		c.JSON(http.StatusInternalServerError, gin.H{ |  | ||||||
| 			"error": "Failed to create request", |  | ||||||
| 		}) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 3. 添加原始请求的查询参数(可选)
 |  | ||||||
| 	req.URL.RawQuery = c.Request.URL.RawQuery |  | ||||||
| 
 |  | ||||||
| 	// 4. 添加必要的请求头(根据目标API要求)
 |  | ||||||
| 	req.Header.Set("User-Agent", "Mozilla/5.0") |  | ||||||
| 	// 可以添加其他必要的headers,如:
 |  | ||||||
| 	// req.Header.Set("Accept", "application/json")
 |  | ||||||
| 
 |  | ||||||
| 	// 5. 发送请求
 |  | ||||||
| 	resp, err := client.Do(req) |  | ||||||
| 	if err != nil { |  | ||||||
| 		c.JSON(http.StatusBadGateway, gin.H{ |  | ||||||
| 			"error": "Failed to fetch data from target API", |  | ||||||
| 		}) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	defer resp.Body.Close() |  | ||||||
| 
 |  | ||||||
| 	// 6. 读取响应体
 |  | ||||||
| 	body, err := io.ReadAll(resp.Body) |  | ||||||
| 	if err != nil { |  | ||||||
| 		c.JSON(http.StatusInternalServerError, gin.H{ |  | ||||||
| 			"error": "Failed to read response body", |  | ||||||
| 		}) |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// 7. 转发响应
 |  | ||||||
| 	c.Data(resp.StatusCode, resp.Header.Get("Content-Type"), body) |  | ||||||
| } |  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user