【发布时间】:2011-07-31 16:28:31
【问题描述】:
我再次尝试使用肥皂方法,但这次我下载了 charles 并观察了我从我的代码中创建的请求。 Chales 显示“解析数据失败(org.xml.sax.saxparser 异常:prolog 中不允许内容)”
这是我的代码:
NSString *soapMsg = [[NSString alloc] initWithFormat:@"\n"
"\n"
“”
"\n"
"%@\n"
"%@\n"
"%@\n"
"%@\n"
"\n"
"\n"
"\n",str1,str2,str3,str4];
NSLog(soapMsg);
NSURL *url = [NSURL URLWithString:@"http://192.168.0.218:84/WebServiceCustomerByAmit/Service.asmx?op=InsertCustomerInformation"];
NSLog(@"url. . . .%@", url);
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSLog(@"req....%@", req);
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
NSLog(@"msgLength. . .%@", msgLength);
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://tempuri.org/InsertCustomerInformation" forHTTPHeaderField:@"SOAPAction"];
[req addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[请求 setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"req....%@", req);
NSError *错误;
NSURLResponse *响应;
//NSData *urlData=[NSURLConnection sendSynchronousRequest:req returnedResponse:&response error:&error];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:req delegate:self];
如果(连接)
{
//webData = [[NSMutableData 数据] 保留];
NSLog(@"连接正常");
}
别的
{
NSLog(@"theConnection 为 NULL");
}
如果(!响应){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"连接错误" message:@"无法连接到 Internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[警报显示];
[警报发布];
}
别的{
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"连接成功" message:@"已连接到 Internet" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert1 显示];
[alert1 发布];
}
}
帮助!!提前谢谢!!
【问题讨论】:
-
尝试删除 SOAP URL 末尾的 op=InsertsCustomerInformation,如果您在服务构造函数中设置断点,您会收到任何信号吗?
-
请将您的代码和 xml 复制并粘贴到问题中。不是他们的图片。
-
@anna: 实际上代码有标签并且不能正确显示。这就是我附上图片的原因。
-
在 SO 编辑器中将其视为“代码”。标签会显示得很好。
-
你构建了一个请求,你实际上在哪里发送任何东西,你从服务中得到什么响应?
标签: iphone