0

连接错误 Error Domain=NSURLErrorDomain Code=-1002“不支持的 URL”UserInfo=0x6a3f420 {NSErrorFailingURLStringKey=http%3A%2F%2F10.101.189.65%3A8090%2Fbusinessservice.svc, NSErrorFailingURLKey=http%3A%2F%2F10.101.189 .65%3A8090%2Fbusinessservice.svc,NSLocalizedDescription=不支持的 URL,NSUnderlyingError=0x6a3f450“不支持的 URL”}

我在访问服务器时收到此错误。

它直接调用了didfailwithError。-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{

NSLog(@"Error with connection %@",error);

}

我可以知道这个错误何时调用!

我创建soapenvelope 并使用方法名称调用soap 请求。并对 url 进行编码并发送到 dot.net 网络服务器

NSString *soapMessage = [self getTestSoapEnvelope];
NSLog(@"soapMessage %@",soapMessage);

NSString *urlString = @"http://systemName:8090/businessservice.svc";
NSString *encodeUrl = (__bridge_transfer NSString *)
CFURLCreateStringByAddingPercentEscapes(NULL,
                                    (__bridge_retained CFStringRef)urlString,
                                    NULL,
                                    (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                    kCFStringEncodingUTF8);

NSURL *url = [NSURL URLWithString:encodeUrl];    
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"ManageCase" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"GET"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];


    theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if( theConnection )
    {
        webData = [NSMutableData data];
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }

请求时间是 GET

无法访问服务器。请任何人就这个问题给我建议。

@提前致谢

4

1 回答 1

0

问题是您正在编码完整的 URL:

NSString *urlString = @"http://systemName:8090/businessservice.svc";
NSString *encodeUrl = (__bridge_transfer NSString *)
CFURLCreateStringByAddingPercentEscapes(NULL, ...

而您应该只对最后一个 URI 部分(包含参数等的部分)进行编码。

在您的情况下,您实际上不需要对您的 URL 进行编码,因为没有以下部分:

@"?param=1&url=newsite.com&title=Post title";

只需传递urlStringURWithString

NSString *urlString = @"http://systemName:8090/businessservice.svc";
NSURL *url = [NSURL URLWithString:urlString];    
于 2012-07-30T15:17:18.807 回答