【问题标题】:problem in posting data in json from iPhone to MySQL/PHP将 json 中的数据从 iPhone 发布到 MySQL/PHP 的问题
【发布时间】:2011-03-11 15:41:09
【问题描述】:

我是 iPhone 开发的新手。以下是将 json 中的数据从 iPhone 发布到 MySQL。数据似乎是从 iPhone 发布的,但发布时出现问题。

**- (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 iphone mysql objective-c json


【解决方案1】:

您不能针对localhost 发帖,因为在这种情况下它是您的手机。

如果没有可用的本地名称解析,请使用运行 PHP/MySQL 脚本的服务器的 IP

【讨论】:

  • 感谢您的反馈。好吧,页面被调用但数据没有被发布。请您进一步指导?
猜你喜欢
  • 2016-12-19
  • 2019-09-09
  • 1970-01-01
  • 2014-01-02
  • 2021-10-03
  • 1970-01-01
  • 2013-05-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多