我在 GAE golang 中有一个简单的函数:
func Call(c appengine.Context, guid string, function string, parameters map[string]string) string {
client:=urlfetch.Client(c)
values := url.Values{}
c.Infof("%v", parameters)
for k, v := range parameters {
values.Set(k, v)
}
c.Infof("%v", values)
resp, err:=client.PostForm("https://blockchain.info/merchant/"+guid+"/"+function, values)
var answer string
if err != nil {
c.Errorf("BlockchainAPI post error: %s", err)
}
c.Infof("%v", resp.Request.PostForm)
[...]
我得到这些打印输出:
2013/10/14 23:17:51 INFO: map[main_password:password]
2013/10/14 23:17:51 INFO: map[main_password:[password]]
2013/10/14 23:17:52 INFO: https://blockchain.info/merchant/guid/function
2013/10/14 23:17:52 INFO: map[]
看起来好像 client.PostForm
没有将 values
传递给请求并且没有在响应中取回它们。什么可能导致此错误?
最佳答案
`client.PostForm` 使用主体而不是 request.PostForm 值。
[文档][1] 中这样说:
// PostForm contains the parsed form data from POST or PUT
// body parameters.
// This field is only available after ParseForm is called.
// The HTTP client ignores PostForm and uses Body instead.
PostForm url.Values
因此您的代码需要更改为:
c.Infof("%v", resp.Request.PostForm)
对于这样的事情(我还没有测试它在字符串处理中的准确性): bd, _ := ioUtil.ReadAll(响应.Body) c.Infof("%v", string(bd[:len(bd)])
关于forms - Google App Engine Go PostForm 不发送任何 url.Values?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19374548/