2011-03-11 72 views
0

我是iPhone開發的新手。以下是從iPhone到MySQL在json中發佈數據。數據似乎從iPhone發佈,但發佈時發生問題。從iPhone發佈數據到json數據到MySQL/PHP的問題

**- (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!!!"; 
}** 

另外,我已經嘗試過上面註釋過的行,但仍然存在問題。

希望得到有利的迴應。謝謝。

+0

出現什麼樣的問題?服務器上是否顯示任何內容? – 2011-03-11 15:46:53

回答

0

你不能針對localhost發帖,因爲在這種情況下,這是你的手機。

使用服務器的PHP的IP/MySQL的腳本運行時,如果沒有本地名稱解析可用

+0

感謝您的反饋。那麼,頁面被調用,但數據不會發布。請您進一步指導? – 2011-03-14 06:39:35