【问题标题】:iOS NSURLConnection, No Response foundiOS NSURLConnection,没有找到响应
【发布时间】:2013-11-28 08:17:45
【问题描述】:

我在NSURLConnection 使用 SOAP 时遇到问题,它在所有应用程序类中都能正常工作,但在一个特定的类中它不起作用,一旦我调用 [connection start];,应用程序就不会调用回调函数(委托功能),我确定我在主线程内运行并且请求正确,我真的需要帮助,谢谢。 代码是:

if(!webData)
    webData = [[NSMutableData alloc] init];

NSString *soapMessage = [NSString stringWithFormat:
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                         "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n"
                         "<soap12:Body>\n"
                         "<ActivateUser xmlns=\"http://tempuri.org/\">\n"
                         "<UserID>%@</UserID>\n"
                         "<MelarityNo>%@</MelarityNo>\n"
                         "<Phone>%@</Phone>\n"
                         "<Name>%@</Name>\n"
                         "<Personal>%@</Personal>\n"
                         "<Rank>%@</Rank>\n"
                         "</ActivateUser>\n"
                         "</soap12:Body>\n"
                         "</soap12:Envelope>\n", @"", self.policeManID, self.policeManPhoneNum, @"", self.policeManPersonalID,@""];

NSURL* url = [NSURL URLWithString:@"link here.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLen = [NSString stringWithFormat:@"%d", [soapMessage length]];
[req addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://tempuri.org/ActivateUser" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLen forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
if(con)
    con = nil;
con = [[NSURLConnection alloc] initWithRequest:req delegate:self];
[con start];

【问题讨论】:

  • 你是否在你的头文件 NSURLConnectionDelegate,NSURLConnectionDataDelegate 中设置了这些委托>
  • 并实现了所有必要的回调??
  • 不,但是没有它们在其他类中也能正常工作!!!
  • 向我们展示您拥有的委托方法。
  • -(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [webData setLength:0]; } -(void) 连接:(NSURLConnection *)connection didReceiveData:(NSData *)data { [webData appendData:data]; } -(void) 连接:(NSURLConnection *)connection didFailWithError:(NSError *)error { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"خطأ في الأتصال" 消息:[错误本地化描述]委托:self cancelButtonTitle:@" حسناً" otherButtonTitles:@"حاول مرة أخرى", nil]; [警报显示]; }

标签: ios iphone soap delegates nsurlconnection


【解决方案1】:

这很可能是因为你的 NSURLConnection 的委托在 NSURLConnection 有时间调用这些方法之前就被释放了。如果没有看到全貌,我无法确定,但你必须看看代表什么时候被释放......

【讨论】:

    【解决方案2】:

    我不确定这是正确的解决方案,但出现的错误可能是这样的。

    如果有空格更改,空格不默认​​

    NSURL* url = [NSURL URLWithString:@"link%20here.asmx"]; 
    

    【讨论】:

      猜你喜欢
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 2021-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      • 1970-01-01
      相关资源
      最近更新 更多