[英]cURL works but none of the rest clients with Go sebserver
有一個簡單的 GO WebServer,它接受圖像作為 POST 請求的一部分。
代碼片段 - 請求被映射到這個函數
func UploadFile(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
successResponse := models.HTTPResponse {
FileURL:"http://testing.com",
}
WrapResponse(w, successResponse, http.StatusOK)
}
響應編寫器功能
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))
}
}
當我使用 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" 響應 -->{"fileURL":" http://testing.com "}%
但是當我從 DHC 休息客戶端嘗試相同的方法時,也嘗試過使用高級休息客戶端沒有響應。
編輯 1:當從其余客戶端觸發時,請求確實到達服務器
我不相信你在做你認為的事情。
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"
不會發送文件“Screen Shot 2015-11-15 at 6.09.58 pm.png”,將文字文本作為正文發送會很麻煩。 您可能想要“-d @'Screen Shot 2015-11-15 at 6.09.58 pm.png'”。
那么你的“好”結果並不是很好,所以你必須弄清楚服務器接收端的錯誤是什么。 由於您使用的 GUI 客戶端可能正在發送文件,而 cURL 則沒有。 而且您的后端似乎接受文本,而不是文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.