From 4ceafe9c5ff3b07a2309185477ac608b61e8cff2 Mon Sep 17 00:00:00 2001 From: xing Date: Wed, 9 Nov 2022 23:06:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- actions/comment.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/actions/comment.go b/actions/comment.go index b02642a..7b5440f 100644 --- a/actions/comment.go +++ b/actions/comment.go @@ -31,7 +31,9 @@ func PostComment(c *gin.Context) { data, err := c.GetRawData() defer func() { if err != nil { - c.String(http.StatusConflict, err.Error()) + c.Writer.WriteHeader(http.StatusConflict) + c.Writer.Header().Set("Content-Type", "text/html; charset=utf-8") + c.Writer.WriteString(err.Error()) } }() if err != nil { @@ -49,6 +51,11 @@ func PostComment(c *gin.Context) { } defer req.Body.Close() req.Header = c.Request.Header.Clone() + home, err := url.Parse(wp.Option["siteurl"]) + if err != nil { + return + } + req.Host = home.Host res, err := cli.Do(req) if err != nil && err != http.ErrUseLastResponse { return @@ -67,8 +74,12 @@ func PostComment(c *gin.Context) { return } up.Host = cu.Host - - ress, err := http.DefaultClient.Get(up.String()) + newReq, err := http.NewRequest("GET", up.String(), nil) + if err != nil { + return + } + newReq.Host = home.Host + ress, err := http.DefaultClient.Do(newReq) if err != nil { return