dave1
(dave@3dissue.com)
October 26, 2012, 12:03pm
1
Hi everyone,
I am seeing some strange behaviour. I am building an api and all the GET requests work well. The post requests are not. When I make a call to the api none of the posted data is available in Yii. So $_POST is empty unless I attach a file to the request. If I post a file as well both $_POST and $FILES are populated. Any thoughts on why this might be happening ?
Here is a sample without the file and response
Request
Request Url: hhhh://********/api/Publication?oauth_apikey=?????????????
Request Method: POST
Status Code: 200
Params: {
"data": "{\"title\":\"new pub\",\"logo\":\"hhhh://s3.amazonaws.co...ccess_Brazil_Graphic.jpg\",\"sources\":[{\"url\":\"toms\",\"enabled\":true}]}"
}
and
print_r($_POST)
returns nothing
Here is a call with the file where the post data is populated
Request Url: hhhh://********cation?oauth_apikey=???????????????
Request Method: POST
Status Code: 200
Files: {
"0": {
"webkitRelativePath": "",
"lastModifiedDate": "2012-10-05T14:10:44.000Z",
"name": "Access_Brazil_Graphic.jpg",
"type": "image/jpeg",
"size": 52114
},
"length": 1
}
Params: {
"data": " {\"title\"=>\"sdfsdf\", \"sources\"=>[{\"url\"=>\"sdfsdf\", \"enabled\"=>true}], \"oauth_apikey\"=>\"c5d?????????????????????????????368264\", \"rule\"=>{}}"
}
Its reponse to print_r($_POST) is
Array([data] = > {
"title" = > "sdfsdf", "sources" = > [{
"url" = > "sdfsdf", "enabled" = > true
}], "oauth_apikey" = > "fsfdf?????????????????", "rule" = > {}
})
Testing I am using the Chrome REST Console and here is the software stack
Yii version 1.1.10
PHP 5.3
Apache
I have changed the links as I cant embed them in a post and the apikey are mashed.
Thanks
Dave
alirz23
(Alirz23)
October 26, 2012, 12:13pm
2
Notice the difference the first one is using json syntax with ( {key:value}
"data": "{\"title\":\"new pub\",\"logo\":\"hhhh://s3.amazonaws.co...ccess_Brazil_Graphic.jpg\",\"sources\":[{\"url\":\"toms\",\"enabled\":true}]}"
this one is using (=>) {key=>value}
"data": " {\"title\"=>\"sdfsdf\", \"sources\"=>[{\"url\"=>\"sdfsdf\", \"enabled\"=>true}], \"oauth_apikey\"=>\"c5d?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?368264\", \"rule\"=>{}}"
just make sure you have the same syntax and try
dave1
(dave@3dissue.com)
October 26, 2012, 1:42pm
3
Thanks for the quick response.
I have made sure the data is the same
Params: {
"data": "{\"title\"=>\"sdfsdf\", \"sources\"=>[{\"url\"=>\"sdfsdf\", \"enabled\"=>true}], \"oauth_apikey\"=>\"c5d49fb3bd78e84dc3489a4e0f869668a2f57128368264\", \"rule\"=>{}}"
}
for both calls but the problem is still there.
Some more data might help.
So here is the request payload from chrome developer Network Tab, everything else is the same bar this:
Simple POST which does not work:
data=%7B%22title%22%3D%3E%22sdfsdf%22%2C%20%22sources%22%3D%3E%5B%7B%22url%22%3D%3E%22sdfsdf%22%2C%20%22enabled%22%3D%3Etrue%7D%5D%2C%20%22oauth_apikey%22%3D%3E%22c5?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />??%22%2C%20%22rule%22%3D%3E%7B%7D%7D
Simple POST with file attached which does work:
------WebKitFormBoundaryfT15s6NZ5JJZ5mPA
Content-Disposition: form-data; name="data"
{"title"=>"sdfsdf", "sources"=>[{"url"=>"sdfsdf", "enabled"=>true}], "oauth_apikey"=>"<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?", "rule"=>{}}
------WebKitFormBoundaryfT15s6NZ5JJZ5mPA
Content-Disposition: form-data; name="Access_Brazil_Graphic.jpg"; filename="Access_Brazil_Graphic.jpg"
Content-Type: image/jpeg
------WebKitFormBoundaryfT15s6NZ5JJZ5mPA--
Any other suggestions ?
UPDATE
Something stupid on my behalf. If I set the Content-type to application/x-www-form-urlencoded it worked.
I have it as form-data
Thanks for the help anyway
Dave