andelf / go-curl

golang curl(libcurl) binding.
Apache License 2.0
485 stars 131 forks source link

Curl --data-urlencode #27

Closed GabMgt closed 9 years ago

GabMgt commented 9 years ago

Hello!

First, thank you for this awesome curl binding, it works very well. But i want to send a POST payload with "\n" in the message.

With command line :

curl -X POST --data-urlencode 'payload={"msg": "First line\nSecond Line"}'

And the \n is encoded : %5Cn

This is the entire payload encoded :

payload=%7B%22msg%22%3A%20%22First%20line%5CnSecond%20Line%22%7D

How to do this with your library please?

GabMgt commented 9 years ago

I tried the function : url.QueryEscape(string) string

But this function translate " " in "+" instead of "%20"

andelf commented 9 years ago

You can use curl.Escape(), like in https://github.com/andelf/go-curl/commit/918707065915e31b415c8e9df97b733aa0d0cb86 . Note that Escape will convert all input characters that are not a-z, A-Z, 0-9, '-', '.', '_' or '~'. In your case, the = will be converted too. (use Escape only on values, don't use it for keys)

GabMgt commented 9 years ago

Thank you!