1 回答

TA貢獻1890條經(jīng)驗 獲得超9個贊
請參閱 Request.Form 的文檔:
// Form contains the parsed form data, including both the URL
// field's query parameters and the POST or PUT form data.
// This field is only available after ParseForm is called.
// The HTTP client ignores Form and uses Body instead.
Form url.Values
特別是“HTTP 客戶端忽略 Form 并使用 Body 代替?!?/p>
有了這條線:
req, _:= http.NewRequest("POST", serverURL+endpoint, nil)
您應該使用它而不是nil:
bytes.NewBufferString(values.Encode())
還要記住,map不能保證的順序。url.Values是map[string][]string。因此,您應該使用 Encode() 一次并在正文和簽名中使用相同的結果。有可能通過使用 Encode() 兩次,順序可能會有所不同。這是 Go 和 PHP 之間的一個重要區(qū)別。
你也應該養(yǎng)成處理的習慣,error而不是忽視它。
- 1 回答
- 0 關注
- 228 瀏覽
添加回答
舉報