2011-03-11 11 views
0

저는 iPhone 개발의 초보자입니다. 다음은 iPhone에서 MySQL로 json의 데이터를 게시하는 방법입니다. 데이터는 iPhone에서 게시 된 것으로 보이지만 게시하는 동안 문제가 발생합니다.iPhone에서 MySQL/PHP로 json의 데이터를 게시 할 때 문제가 발생했습니다.

**- (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

가능 지역 이름 확인이없는 경우/MySQL은 스크립트가 실행되고있는 서버 당신의 PHP의 IP? 서버에 아무것도 나타나지 않습니까? –

답변

0

귀하의 휴대 전화와 마찬가지로 localhost에 대한 게시물을 게시 할 수 없습니다.

사용 당신은 어떤 종류의 문제가 발생

+0

의견을 보내 주셔서 감사합니다. 페이지가 호출되었지만 데이터가 게시되지 않았습니다. 더 자세히 안내해 주시겠습니까? –

관련 문제