dpxkkhu1812 2019-03-19 18:55
浏览 394

http查询字符串:问号变为%3

Attempting to append to an existing queryString, but '?' that proceeds the query string is being replaced with '%3'

 server := "server.com"
 endpoint:= "/buildWithParameters?token=<top_secret>" 

// concat server and build job
    u, err := url.Parse(server)
    u.Path = path.Join(u.Path, endpoint)
    endpoint := u.String()

    // since we are appending to existing querystring, request is needed for parsing
    req, err := http.NewRequest("POST", endpoint, nil)
    if err != nil {
        return fmt.Errorf("Error creating post request: (%v)", err)
    }

    // read existing query string
    q := req.URL.Query()


    q.Add("key", "value")

    req.URL.RawQuery = q.Encode()


    log.Println(req.URL.String())

The output is:

https://server.com/job/jobbyjob/buildWithParameters%3Ftoken=<top_secret>?key=value
  • 写回答

3条回答 默认 最新

  • dongliaoqiang8524 2019-03-19 18:58
    关注

    That's because you're appending the query string to the path, so the library is correctly escaping ? to make for a valid URL. If you want token=<top_secret> to be treated as part of the query, you need to add it to the query instead:

    endpoint:= "/buildWithParameters" 
    
    // ... 
    
    q.Add("token", "<top_secret>")
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真