我在使用SOAP的NSURLConnection
中遇到问题,它在所有应用类中都能正常运行,但是在一个特定的类中它不起作用,一旦我调用[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];
答案 0 :(得分:0)
最有可能发生这种情况,因为NSURLConnection的委托在NSURLConnection有时间调用这些方法之前被释放。如果没有看到整个图片,我无法确定,但你必须看看代表何时被释放......
答案 1 :(得分:0)
我不确定这是正确的解决方案,但出现的错误可能就是这样。
如果空格更改为
,则空格不会默认NSURL* url = [NSURL URLWithString:@"link%20here.asmx"];