2012-05-31 83 views
0

我開發了使用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]; 
      } 

謝謝!

+0

如何使用'error:'參數(而不是傳遞nil)來查看它是否報告錯誤? –

+0

試試這個http://stackoverflow.com/a/9930735/1344459 – hightech

回答

1

我會建議使用– stringByAddingPercentEscapesUsingEncoding:建立自己的網址,因爲它很可能需要一些轉義:

NSString* urlString = [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]; 

NSURL *url = [[NSURL alloc] initWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
+0

非常感謝你! – Dinesh

1

試試下面的代碼;

NSString *urlString = [@"your url addres as string" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
NSURL *myUrl = [NSURL URLWithString:urlString]; 
NSURLRequest *request = [NSURLRequest requestWithURL:myUrl]; 

如果你的網址有空格,這將工作..或者你應該看看NSString函數。

+0

+ 1,謝謝你的回答 – Dinesh