Thursday, April 12, 2012

Encoding json data as x-www-form-urlencoded

I am trying to POST wih curl some data. The source data is in JSON, but I want to post with content-type application/x-www-form-urlencoded. I am trying to do it like this:



curl -X POST $URL --data-urlencode "@$data.json" --header "Content-Type: application/x-www-form-urlencoded"


This is data.json:



{
"action" : "deploy_from_scratch_with_bundle",
"pusher" : { "email" : "my@email.com" },
"ref" : "refs/heads/master",
"repo_choice" : "LOCAL"
}


But this is not working: urlparse.parse_qs (python) is complaining about ValueError.



The received data (before parse_qs) is:



%7B%0A%20%20%22action%22%20%20%20%20%20%20%3A%20%22deploy%5Ffrom%5Fscratch%5Fwith%5Fbundle%22%2C%0A%20%20%22pusher%22%20%20%20%20%20%20%3A%20%7B%20%22email%22%20%3A%20%22my%40email%2Ecom%22%20%7D%2C%0A%20%20%22ref%22%20%20%20%20%20%20%20%20%20%3A%20%22refs%2Fheads%2Fmaster%22%2C%0A%20%20%22repo%5Fchoice%22%20%3A%20%22LOCAL%22%0A%7D%0A


What am I doing wrong here?





No comments:

Post a Comment