开发者

php $_POST can't get info from ASIFormDataRequest

开发者 https://www.devze.com 2023-03-24 06:09 出处:网络
So in my implementati开发者_开发技巧on file, i have NSString *post = [NSString stringWithFormat:@\"json=%@\",jsonString];

So in my implementati开发者_开发技巧on file, i have

NSString *post = [NSString stringWithFormat:@"json=%@",jsonString];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO];
NSMutableData *postMutData = [[NSMutableData alloc] initWithData:postData];
ASIFormDataRequest *asi_request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlString]];
[asi_request setDidFinishSelector:@selector(gotMyInfo:)];
[asi_request setPostBody:postMutData];
[asi_request setDelegate:self];
[asi_request startAsynchronous];

and in my php, i have

$json = $_POST['json'];
$info = json_decode($json);

but i get an error: Undefined index 'json' it's odd because i check the post with

$input = file_get_contents('php://input');
echo $input;

and it shows the json={....} properly. I know i can just use the $input and decode the json from there but it seems "ugly". Does anybody know why $_POST isn't working for this??

Thanks in advance


check post_max_size in php.ini.

it's

; Maximum size of POST data that PHP will accept.
post_max_size = 8M

by default. try to change 8M to (for example) 20M


Wow i figured out the problem.. I used the setPostBody:postMutData which doesn't send form data to the php, so php won't recognize it with $_POST I needed to do

[asi_request addPostValue:jsonString forKey:@"json"]; 

then it'll send the ?json={...}

0

精彩评论

暂无评论...
验证码 换一张
取 消