我过去曾多次使用 ASIHTTPRequest 将数据发布到 php 脚本,没有任何问题。这是我第一次尝试发送 JSON,但我无法让它工作。
NSError *error = nil;
NSMutableDictionary *jsonDict = [NSMutableDictionary dictionaryWithObjects:objectArray forKeys:keyArray];
[jsonDict setObject:email forKey:@"email"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:NSJSONWritingPrettyPrinted error:&error];
NSURL *url = [NSURL URLWithString:@"http://192.168.1.12:8888/Folder/script.php"];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
[request appendPostData:jsonData];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request setCompletionBlock:^{
NSString *responseString = [request responseString];
NSLog(@"finished text: %@", responseString);
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSLog(@"failed: %@", error);
}];
[request startAsynchronous];
现在的 PHP 脚本只是
<?php print_r($_POST); ?>
这导致:Array ()。什么都没有通过。任何想法可能是什么问题?