iPhoneアプリからphpサーバーにjsonを送信しようとすると、少し問題が発生します。
NSData オブジェクトを作成します
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:test];
私はそれをウェブサーバーに送信します
-(void)send:(NSData *)jsonData{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL
URLWithString:@"http://localhost:8888/jsonserver/try2.php"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:jsonData];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
}
私のウェブサーバー
<?php
$json = $_POST['json'];
$person = json_decode($json);
$file = fopen('test.txt','w+');
fwrite($file, $person);
fclose($file);
?>
サーバーはフォルダーにファイルを正しく作成しますが、ファイルは空です
(サーバーに送信される前の私のjsonファイルは、["a","b","c"]のようなものです)
助けてくれてありがとう:P