作者:mobiledu2502877427 | 来源:互联网 | 2023-09-18 19:55
我通过objective-C创建了以下POST方法-(IBAction)postLocation:(id)sender{NSString*latitude@37.3229978
我通过objective-C创建了以下POST方法
-(IBAction) postLocation: (id) sender{
NSString *latitude = @"37.3229978";
NSString *lOngitude= @"-122.0321823";
NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mydomain.me/webservice.php"]];
[request setHTTPMethod:@"POST"];
NSString *post =[[NSString alloc] initWithFormat:@"latitude=%@lOngitude=%@submit",latitude,longitude];
[request setHTTPBody:[post dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response;
NSError *err;
NSData *respOnseData= [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
}
我的PHP代码是:
if (isset($_POST['submit']){
//it doesn't get into this if statement
$latitude = $_POST['latitude'];
$lOngitude= $_POST['longitude'];
}
问题是,为什么PHP代码不能进入if语句?我在哪里可以通过Objective-C声明“提交”?
解决方法:
POST的查询字符串不包含提交密钥.您应该将其更改为以下内容
NSString *post =[[NSString alloc] initWithFormat:@"latitude=%@&lOngitude=%@&submit=",latitude,longitude];