douxingsuo8809 2018-05-24 11:57
浏览 84
已采纳

Golang中的http.NewRequest将一些租船人转换为%值

go version go1.8.1 windows/amd64

"net/http" package used to build http request.

req, err := http.NewRequest("GET",`http://domain/_api/Web/GetFolderByServerRelativeUrl('` + root_folder_url + `')?$expand=Folders,Files`, nil)

Here if I print url it shows

http://domain/_api/Web/GetFolderByServerRelativeUrl%28%27rooturl%27%29?$expand=Folders,Files

Not understanding why url parser is replacing ' to %27 here. Whereas I need ' to be sent as is while requesting.

  • 写回答

1条回答 默认 最新

  • douguazhi5966 2018-05-24 13:31
    关注

    The http.NewRequest function calls url.Parse to set the Request.URL. The URL.RequestURI method is called to get the request URI written to the network.

    An application can override any transformation made by Parse/RequestURI by setting the request URL Opaque field:

    req, err := http.NewRequest("GET", "http://domain/", nil)
    if err != nil {
       // handle error
    }
    req.URL.Opaque = `/_api/Web/GetFolderByServerRelativeUrl('` + root_folder_url + `')?$expand=Folders,Files`
    

    In this snippet, the argument to NewRequest specifies the protocol and host for the request. The opaque value specifies the request URI written to the network. The request URI does not include host or protocol.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?