将json格式的数据从iPhone发布到MySQL/PHP时出现问题
我是iPhone开发的新手。以下是将json格式的数据从iPhone发布到MySQL的步骤。数据似乎是从iPhone发布的,但发布时出现问题将json格式的数据从iPhone发布到MySQL/PHP时出现问题,php,iphone,mysql,objective-c,json,Php,Iphone,Mysql,Objective C,Json,我是iPhone开发的新手。以下是将json格式的数据从iPhone发布到MySQL的步骤。数据似乎是从iPhone发布的,但发布时出现问题 **- (IBAction) btnPostDataPressed : (id) sender { NSURL *objUrl = [NSURL URLWithString : @"http://localhost/test_questionnaire/update.php"] ; NSMutableURLRequest *theRe
**- (IBAction) btnPostDataPressed : (id) sender {
NSURL *objUrl = [NSURL URLWithString : @"http://localhost/test_questionnaire/update.php"] ;
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL : objUrl] ;
[theRequest setHTTPMethod : @"POST"];
[theRequest setValue : @"application/json"
forHTTPHeaderField : @"Content-Type"];
[theRequest setTimeoutInterval:10];
//NSData *myData = [[NSString alloc] initWithString:@"nasir here"];
//[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];
NSString *stringData = [[NSString alloc] initWithString:@"nasir here"];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObject:stringData forKey:@"code"];
NSString *jsonString = [jsonDictionary JSONRepresentation];
NSString *strHttpBody = [NSString stringWithFormat:@"%@", jsonString];
[theRequest setHTTPBody:[strHttpBody dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
textView.text = @"data successfully posted!!!";
}**
此外,我也尝试了上面注释掉的行,但仍然存在问题
希望得到积极的回应。谢谢。您不能针对本地主机发帖,因为在这种情况下,它是您的手机
使用运行PHP/MySQL脚本的服务器的IP,如果没有可用的本地名称解析会出现什么问题?服务器上有什么显示吗?谢谢你的反馈。嗯,页面被调用,但数据未发布。请你进一步指导好吗?