简体   繁体   English

iOS NSURLConnection,未找到响应

[英]iOS NSURLConnection, No Response found

i have a problem in NSURLConnection with SOAP, it works properly in the all app classes, but in one specific class it doesn't work, once i call [connection start]; 我在使用SOAP的NSURLConnection时遇到问题,它在所有应用程序类中均正常工作,但是在一个特定的类中,一旦我调用[connection start]; ,它将不起作用[connection start]; the app don't call the call back functions (delegate functions) and i'm sure that i'm running inside the main thread and the request it right, i really need help, thanks. 该应用程序不会调用回调函数(委托函数),并且我确定我在主线程中运行并且要求正确,我真的需要帮助,谢谢。 the code is: 代码是:

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

Most probably that is happening because the delegate of your NSURLConnection is released before NSURLConnection has the time to call these methods. 这很有可能是由于NSURLConnection的委托在NSURLConnection有时间调用这些方法之前被释放的。 I can't tell for sure without seeing the whole picture, but you have to see when the delegate gets released... 我不能肯定地说不看全貌,但是您必须看到委托何时被释放...

I don't sure this to right solution but the bug arise may be like this. 我不确定这是正确的解决方案,但是出现的错误可能是这样的。

Space doesn't default if have space change to 如果将空间更改为,则空间不会默认

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM