Я новичок в iPhone Development. Ниже перечислены данные в 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!!!";
}**
Кроме того, я попытался с комментариями выше, но проблемы остаются.
В ожидании положительного ответа. Спасибо.
Вы не можете отправлять сообщения против localhost
, так как в этом случае это ваш телефон.
Использовать IP-адрес сервера, на котором запущен ваш PHP/MySQL script, если у вас нет разрешения на локальное имя