在golang中解析带有标点符号的发布数据不正确

I know how to parse post data in golang

r.ParseForm()
pid := r.PostFormValue("pid")
code := r.PostFormValue("code")
lang := r.PostFormValue("lang")
author := r.PostFormValue("author")

But the post data is pid=1&code=#include <stdio.h>\x0Aint main()\x0A{\x0A\x09printf(\x223\x5Cn\x22);\x0A\x09return 0;\x0A}&lang=c&author=11(this is obtained from nginx log)

So when I parse the data, it could be wrong. The parsed data of code is

#include <stdio.h>
int main()
{
    printf("3
")

instead of

#include <stdio.h>
int main()
{
    printf("3
");
    return 0;
}

So how can I fix this problem?

You're passing the raw code, which could be unsafe, your problem is because of this:

https://golang.org/src/net/url/url.go?s=21047:21092#L761

enter image description here

I would suggest that you base64encode your log code and then decode it in your handler.

import "encoding/base64"

...

code, err := base64.RawURLEncoding.DecodeString(r.PostFormValue("code"))
    if err != nil {
        // handle error
    }

Then your request should look like this:

curl --data "pid=1&code=I2luY2x1ZGUgPHN0ZGlvLmg-XHgwQWludCBtYWluKClceDBBe1x4MEFceDA5cHJpbnRmKFx4MjIzXHg1Q25ceDIyKTtceDBBXHgwOXJldHVybiAwO1x4MEF9&lang=c&author=11" http://localhost:8080