无法使用soap信封和方法名称命中服务器

时间:2012-07-30 15:02:17

标签: iphone ipad wsdl

  

连接错误错误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   “不支持的网址”}

当我点击服务器时,我收到此错误。

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

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

}

我可以知道这个错误的来电!

我创建了soapenvelope并使用方法名称调用soap请求。并编码网址并发送到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

无法点击服务器。请任何人就此问题向我提出建议。

@thanks提前

1 个答案:

答案 0 :(得分:0)

问题是您要编码完整的网址:

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];