我試圖使登錄表單使用http請求來檢查用戶名從外部服務器&密碼但響應給出<>發送HTTP請求返回<>
- (IBAction)getlogin:(UIButton *)sender {
NSString *rawStrusername = [NSString stringWithFormat:@"username=%@",_username.text];
NSString *rawStrpassword = [NSString stringWithFormat:@"password=%@",_password.text];
NSString *post = @"rawStrusername&rawStrpassword";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
/*
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];*/
NSURL *url = [NSURL URLWithString:@"http://www.othaimmarkets.com/my_services_path/user/login"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
/*[request setValue:postLength forHTTPHeaderField:@"Content-Length"];*/
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSLog(@"responseData: %@", responseData);
}
任何幫助,建議或實施例,將不勝感激
如果服務器返回正確的請求不正確的答覆,這可能是一個服務器問題。 –
我通過firefox {海報}插件測試了服務器,並返回了我的結果 URL:http://www.othaimmarkets.com/my_services_path/user/login(OR http://www.othaimmarkets.com/my_services_path/user/ login.json) 內容類型:應用程序/ x-WWW窗體-urlencoded 名稱:用戶名 值:[email protected] 名:密碼 值:29378960 操作:POST –
然後檢查結果你發送來幫助你調試。 –