我正在构建一个 iOS 应用程序/网络服务。iOS 应用程序将数据发送到 php 脚本,如下所示:
NSError* error = nil;
NSURLResponse *res ponse = nil;
NSArray * keys = [NSArray arrayWithObjects:@"addr", @"date", @"o_cond", nil];
NSArray * values = [NSArray arrayWithObjects:addr, date, o_cond, nil];
NSDictionary * info = [NSDictionary dictionaryWithObjects:values forKeys:keys];
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:info options:NSJSONWritingPrettyPrinted error:&error];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://myaddr.com/sendEmail.php"]];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:jsonData];
[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
php收到了数据:
<?php
// Get all the posted vars
$jsonInput = file_get_contents('php://input');
$decoded = json_decode($jsonInput, true);
$body = "Inspection Results for " . $decoded->{'addr'} . "\n\n";
$body = $body . "Inspection date and time: " . $decoded->{'date'} . "\n\n";
$body = $body . "Overall condition of asset: " . $decoded->{'o_cond'} . "\n\n"; ?>
但由于某种原因,我永远无法在 php 端接收数据。有谁看到这里出了什么问题?
谢谢