问题
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