1

我进行了很多搜索,但我找到的代码片段似乎都不适合我。我在 xcode 中有以下片段,可在我的 iPhone 应用程序中运行:

NSURL *url = [NSURL URLWithString:@"http://blah.blah.com/rec.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
NSData *body = [@"data=crap" dataUsingEncoding:NSUTF8StringEncoding];
NSString *bodyLength = [NSString stringWithFormat:@"%d", [body length]];
[request setValue:bodyLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];    
[request setHTTPBody:body];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL];

rec.php 调用正常,但发布数据没有通过。条目 $_POST['data'] 为空。谁能让我知道我做错了什么?

4

0 回答 0