简体   繁体   English

cURL 可以工作,但其他客户端都没有使用 Go sebserver

[英]cURL works but none of the rest clients with Go sebserver

Having a simple GO WebServer which accepts an image as part of POST request.有一个简单的 GO WebServer,它接受图像作为 POST 请求的一部分。

Code snippet - Request is mapped to this function代码片段 - 请求被映射到这个函数

 func UploadFile(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
        successResponse := models.HTTPResponse {
            FileURL:"http://testing.com",
        }
        WrapResponse(w, successResponse, http.StatusOK)
    }

Response writer function响应编写器功能

func WrapResponse(writer http.ResponseWriter, content interface{}, status int) {    
    writer.Header().Set("Content-Type", "application/json")
    writer.WriteHeader(status)
    // Content is a struct Response { fileURL string }  
    responseJson, err := json.Marshal(content)  
    CheckError(err, "Error wrapping response")  
    writer.Write(responseJson) 
    }

    func CheckError(err error, msg string) {    
    if err != nil {         
    panic(fmt.Sprintf("%s : %s", msg, err))     
    } 
    }

When i hit the URL using cURL as below the response is 200 OK (as expected)当我使用 cURL 访问 URL 时,响应为 200 OK(如预期)

curl -X POST -d@ "Screen Shot 2015-11-15 at 6.09.58 pm.png" http://localhost:8000/image/agent123/property --header "Content-Type:image/png" --header "X-User-Agent:agent-php" response -->{"fileURL":" http://testing.com "}% curl -X POST -d@ "Screen Shot 2015-11-15 at 6.09.58 pm.png" http://localhost:8000/image/agent123/property --header "Content-Type:image/png" -- header "X-User-Agent:agent-php" 响应 -->{"fileURL":" http://testing.com "}%

Entire cURL request & response整个 cURL 请求和响应冗长的

But when i try the same from DHC rest client, have also tried with advanced rest client getting no response.但是当我从 DHC 休息客户端尝试相同的方法时,也尝试过使用高级休息客户端没有响应。

通过 DHC 的相同请求

Edit 1: Request does reach the server when fired from rest clients编辑 1:当从其余客户端触发时,请求确实到达服务器

I do not believe you're doing what you think you are.我不相信你在做你认为的事情。

curl -X POST -d "Screen Shot 2015-11-15 at 6.09.58 pm.png" http://localhost:8000/image/agent123/property --header "Content-Type:image/png" --header "X-User-Agent:agent-php" 

Will not send the file "Screen Shot 2015-11-15 at 6.09.58 pm.png", it's gonig to send the literal text as the body.不会发送文件“Screen Shot 2015-11-15 at 6.09.58 pm.png”,将文字文本作为正文发送会很麻烦。 You probably want "-d @'Screen Shot 2015-11-15 at 6.09.58 pm.png'".您可能想要“-d @'Screen Shot 2015-11-15 at 6.09.58 pm.png'”。

Which then your "good" result is not exactly good, so you have to figure out what the bug is at the receiving end on the server.那么你的“好”结果并不是很好,所以你必须弄清楚服务器接收端的错误是什么。 As the GUI client you're using is probably sending the file, whereas cURL is not.由于您使用的 GUI 客户端可能正在发送文件,而 cURL 则没有。 And your backend seems to accept text, not files.而且您的后端似乎接受文本,而不是文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM