Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用带网关保护的JSON Webservice时,在IOS中没有响应_Ios_Iphone_Objective C_Json_Web Services - Fatal编程技术网

使用带网关保护的JSON Webservice时,在IOS中没有响应

使用带网关保护的JSON Webservice时,在IOS中没有响应,ios,iphone,objective-c,json,web-services,Ios,Iphone,Objective C,Json,Web Services,下面的代码是简单的登录应用程序。我使用Post请求传递用户名和密码以获取详细信息。但我从web服务得到@“”响应 email= emailTextField.text; password=passwordTextfield.text; NSString *post = [[NSString alloc] initWithFormat:@"UserName=%@&Password=%@",email,password]; NSData *postData = [post dataUsi

下面的代码是简单的登录应用程序。我使用Post请求传递用户名和密码以获取详细信息。但我从web服务得到@“”响应

email= emailTextField.text;
password=passwordTextfield.text;

NSString *post = [[NSString alloc] initWithFormat:@"UserName=%@&Password=%@",email,password];

NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSURL *url = [NSURL URLWithString:@"http:Gateway/api/json"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
[theRequest setHTTPBody:postData];

NSURLResponse *response;// = [[NSURLResponse alloc] init];

NSError *error;// = [[NSError alloc] init;

NSData *urlData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];

NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

NSLog(@"Login response: is %@",str);

要向服务器提供身份验证凭据,请使用NSURLConnection委托

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

    if ([challenge previousFailureCount] == 0) {

        NSURLCredential *credential;
        credential = [NSURLCredential credentialWithUser:userName password:password persistence:NSURLCredentialPersistenceNone];
        [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
    } else {
        [[challenge sender] cancelAuthenticationChallenge:challenge];
    }
}

查看提供身份验证的方法。我应该调用哪种方法来传递用户名和密码凭据?NSLog(@“errot:%@”,error);这是获取操作无法完成的错误。(NSURErrorDomain错误-1012。)“用户信息=0xa219390{NSErrorFailingURLKey=http://1,NSERRORFAILINGURSTRINGKEY=http:///api/json/reply/Customer/?,NSUnderlyingError=0x8f3e3c0“该操作无法完成。(KCFerrorDomainCFN网络错误-1012)。”