【问题标题】:Unable to hit Server with soap envelop and method name无法使用肥皂信封和方法名称访问服务器
【发布时间】:2012-07-28 06:36:50
【问题描述】:

连接错误 错误域=NSURLErrorDomain 代码=-1002 “不支持的 URL”用户信息 = 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 “不支持的网址”}

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

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

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

}

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

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

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

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

@提前谢谢

【问题讨论】:

    标签: iphone ipad wsdl


    【解决方案1】:

    问题是您正在编码完整的 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";
    

    只需将urlString 传递给URWithString

    NSString *urlString = @"http://systemName:8090/businessservice.svc";
    NSURL *url = [NSURL URLWithString:urlString];    
    

    【讨论】:

    • 感谢重播!我尝试不编码我得到了同样的错误。 (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ NSLog(@"Error with connection %@",error); }
    • 连接错误 Error Domain=kCFErrorDomainCFNetwork Code=303 “操作无法完成。(kCFErrorDomainCFNetwork 错误 303。)” UserInfo=0x6a37870 {NSErrorFailingURLKey=systemName:8090/businessservice.svc, NSErrorFailingURLStringKey=systemName:8090/businessservice.svc}
    • 如您所见,这是一种完全不同的错误。这似乎与 NSURLMutableRequest 中的一个错误有关:stackoverflow.com/questions/3469061/…
    • 这个错误是我缺少任何需要发送的 forHTTPHeaderField!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    相关资源
    最近更新 更多