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 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败