drci47425 2013-10-15 06:24 采纳率: 100%
浏览 49

Google App Engine Go PostForm不发送任何url.Values吗?

I have a simple function in 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)
    [...]

I get these printouts:

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[]

It looks as if client.PostForm does not pass values to the request and not get them back in response. What can be causing this error?

  • 写回答

1条回答 默认 最新

  • dongya1228 2013-10-15 14:06
    关注

    `client.PostForm` uses the body not the request.PostForm values.

    It says so in the [documentation][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
    

    So your code needs to change from:

    c.Infof("%v", resp.Request.PostForm)
    

    To something like this (I haven't tested it for accuracy in the string handling): bd, _ := ioUtil.ReadAll(resp.Body) c.Infof("%v", string(bd[:len(bd)])

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器