我開發了使用PHP和MySQL數據庫的iOS Web應用程序,我的問題是nsurl請求獲取值到PHP文件沒有響應和不工作,但是,我在命令提示符URL中打印並複製URL粘貼和去瀏覽器成功updated.but,沒有更新,沒有反應nsurl請求我的代碼中有什麼問題?任何人都可以幫助我!NSURLRequest不工作
NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://192.168.1.20:90/inkfreakz/update.php?fname=%@&lname=%@&gender=%@&dob=%@&uname=%@&email=%@&city=%@&zcode=%@&state=%@&count=%@&tattoo=%@&aboutme=%@&id=%@",txt_first.text,txt_last.text,txt_gender.text,txt_birth.text,txt_user.text,txt_email.text,txt_city.text,txt_zip.text,txt_state.text,txt_country.text,txt_tatoo.text,txt_about.text,[results objectAtIndex:13]]];
NSLog(@"%@",[NSString stringWithFormat:@"http://192.168.1.20:90/inkfreakz/update.php?fname=%@&lname=%@&gender=%@&dob=%@&uname=%@&email=%@&city=%@&zcode=%@&state=%@&count=%@&tattoo=%@&aboutme=%@&id=%@",txt_first.text,txt_last.text,txt_gender.text,txt_birth.text,txt_user.text,txt_email.text,txt_city.text,txt_zip.text,txt_state.text,txt_country.text,txt_tatoo.text,txt_about.text,[results objectAtIndex:14]]);
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:5];
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSString* newStr = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
if(newStr.length==0)
{
[email protected]"Can't Communicate with Server!";
lbl_status.hidden=NO;
[my_scroll_view setContentOffset:CGPointMake(0,0) animated:YES];
}
else {
lbl_status.text=newStr;
lbl_status.hidden=NO;
[my_scroll_view setContentOffset:CGPointMake(0,0) animated:YES];
}
謝謝!
如何使用'error:'參數(而不是傳遞nil)來查看它是否報告錯誤? –
試試這個http://stackoverflow.com/a/9930735/1344459 – hightech