ASIFormDataRequest doesn't send post values

时光总嘲笑我的痴心妄想 提交于 2020-01-03 06:18:29

问题


I try to send some values using ASIFormDataRequest. The problem is that even though the php script is executed no post data is received.

Here is what I do:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request startSynchronous];

In order to check what the server receives I have the following php test script:

$handle = fopen("output.txt", "w");
fwrite($handle, count($_POST)."\n");
fwrite($handle, count($_GET)."\n");
fwrite($handle, count($_FILES)."\n");
foreach ($_POST as $key => $value)
{
 fwrite($handle, "POST $key=$value\n");
}
foreach ($_GET as $key => $value)
{
 fwrite($handle, "GET $key=$value\n");
}
fclose($handle);

The same script works with the following html fragment:

<FORM action="http://......."
       enctype="multipart/form-data"
       method="post">
   <P>
   What is your name? <INPUT type="text" name="submit-name"><BR>
   <INPUT type="submit" value="Send"> <INPUT type="reset">
 </FORM>

Because the html fragment works with the php script I suspect the php and server are not the problem.

But I don't have the slightest idea why ASIFormDataRequest doesn't work when called from my iPhone.

Could somebody please help me?

Regards, Sascha


回答1:


I finally managed to find the reason: the server was redirecting from site.com to www.site.com and losing the post values because of that. Without this redirect everything works fine. Hope this helps.



来源:https://stackoverflow.com/questions/4274802/asiformdatarequest-doesnt-send-post-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!