dp815292 2016-11-24 12:11
浏览 57

http NewRequest获得意外字符

I try to parse a page with this code :

client := &http.Client{}
profile := getEpiURL(login)

log.Print("Fetch " + profile)
req, err := http.NewRequest("GET", profile, nil)
if err != nil {
    log.Fatal(err)
}
req.AddCookie(cookieSessionIntra)
body, _ := httputil.DumpRequestOut(req, true)

With this as getEpiURL function :

func getEpiURL(login string) (url string) {
    url = "https://********/user/" + login + "/?format=json"
    return
}

And when i look at the output the profile variable is good, but in the Request it seems obviously wrong...

2016/11/24 12:53:53 Fetch https://********/user/le****in-vi**rd@e*******/?format=json

Then the debug for the request prints me :

GET /user/%00l%*****0o%*00.%00c***0-%00v%00i%0*a%00r%00d%00@%00e%00i%00t%00e%00c%0***0.%0***00/?format=json HTTP/1.1 Host: ****** User-Agent: Go-http-client/1.1 Cookie: PHPSESSID=********* Accept-Encoding: gzip

  • 写回答

1条回答 默认 最新

  • dounanyin3179 2016-11-24 12:45
    关注

    I think your original string somehow contains NUL characters. Try this out in the playground:

    func main() {
        req, err := http.NewRequest("GET", "https://some/normal/path", nil)
        if err != nil {
            log.Fatal(err)
        }
        body, _ := httputil.DumpRequestOut(req, true)
        fmt.Printf("Hello, playground, %q", body)
    }
    

    You'll get:

    "GET /normal/path HTTP/1.1
    Host: some...
    

    Now try it with a string in which you inserted NUL characters:

    req, err := http.NewRequest("GET", "https://some/\000n\000o\000rmal/path", nil)
    

    ...

    "GET /%00n%00o%00rmal/path HTTP/1.1
    Host: some...
    

    Not quite sure how your string ended up containing those. Read more about percent encoding.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器