golang - HTTP客户端总是转义该URL [英] golang - HTTP client always escaped the URL

查看:756
本文介绍了golang - HTTP客户端总是转义该URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于golang HTTP客户端,有没有办法转义请求的URL。

例如,对URL/ test(a)的请求会被转义为/ test%28a%29 。

我正在运行 https://github.com/cmpxchg16/gobench中的代码

Is there anyway for golang HTTP client,not to escape the requested URL.
For example, a request for URL "/test(a)", gets escaped to "/test%28a%29".
I'm running the code from https://github.com/cmpxchg16/gobench

推荐答案

您可以设置一个不透明的网址。

You can set an opaque url.

假设您希望url指向 http://example.com/test(a),您可以这样做:

Assuming you want the url to point to http://example.com/test(a) you would want to do:

req.NewRequest("GET", "http://example.com/test(a)", nil)
req.URL = &url.URL{
    Scheme: "http",
    Host:   "example.com",
    Opaque: "//example.com/test(a)",
}
client.Do(req)

示例:http://play.golang.org/p/09V67Hbo6H

文档: http://golang.org/pkg/net/url/#URL

这篇关于golang - HTTP客户端总是转义该URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆