-1

我收到的错误代码:

错误域=ASIHTTPRequestErrorDomain 代码=1“发生连接失败”UserInfo=0x6993280 {NSUnderlyingError=0x6d520c0“操作无法完成。(kCFErrorDomainCFNetwork 错误 306。)”

我没有选择,只有 ASIHTTPRequest。我已经开发了该应用程序,无法使用任何替代方案。

目前我们正在使用 iOS 版本 5.1.1

一年前,我使用相同的 iOS 3 代码开发了该应用程序,并且运行正常。现在相同的代码无法工作。我怀疑最新的 iOS 版本会发生这种情况。

此代码在没有代理设置但不适用于代理设置的情况下运行良好。

_method = [NSStringstringWithFormat:@"http://%@%@", _settings.ServerLocation, _settings.WebServicePath];
NSLog(_method);

NSString *soapMessage = [NSStringstringWithFormat:@"%@%@%@",
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                         "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                         "<soap:Body>\n",
                         parameters,
                         @"</soap:Body>\n"
                         "</soap:Envelope>\n"];
//NSLog(@"soapMessage : %@",soapMessage);

NSURL *url = [NSURLURLWithString:_method];

ASIHTTPRequest *request = [ASIHTTPRequestrequestWithURL:url];

if(_settings.IsProxy)
{
    [request setProxyHost:_settings.HostIP];
    [request setProxyPort:(NSInteger)_settings.Port];
}   

constchar *utfString = [soapMessage UTF8String];
NSMutableData *req = [NSDatadataWithBytes:utfString length:strlen(utfString)]; 

[request addRequestHeader:@"Content-Type"value:@"text/xml; charset=utf-8"];
[request addRequestHeader:@"Content-Length"value:[NSStringstringWithFormat:@"%d", [soapMessage length]]]; 
[request addRequestHeader:@"SOAPAction"value:action]; 
if(_settings.IsProxy) 
{
    [request addRequestHeader:@"Host"value:_settings.HostIP]; 
}

[request setPostLength:[soapMessage length]];
[request setRequestMethod:@"POST"]; 
[request setPostBody:req];
[request setTimeOutSeconds:5];
[request setNumberOfTimesToRetryOnTimeout:1];

if(_settings.IsProxy)
{
    if([_settings.Usernamelength] > 0) 
    {
        [request setProxyUsername:_settings.Username];
    }

    if([_settings.Passwordlength] > 0) 
    {
        [request setProxyPassword:_settings.Password];
    }

}

//[request setValidatesSecureCertificate:NO];
[request setDelegate:self];
[request startAsynchronous];
4

1 回答 1

0

我已经下载了ASIHTTPRequest 库,它按我的预期工作。

在它起作用之前,我已经删除了下面的代码行

[request addRequestHeader:@"Host"value:_settings.HostIP]; 
于 2012-09-04T07:06:52.820 回答