Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone &引用;缺少根元素";iOS中的Soap请求_Iphone_Objective C_Ios_Web Services_Soap - Fatal编程技术网

Iphone &引用;缺少根元素";iOS中的Soap请求

Iphone &引用;缺少根元素";iOS中的Soap请求,iphone,objective-c,ios,web-services,soap,Iphone,Objective C,Ios,Web Services,Soap,我有SOAP Web服务,并尝试连接它。但SOAP响应包含“System.Xml.XmlException:缺少根元素” 我的obj-c代码。怎么了 NSString *soapMessage = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<soap:Envelope xm

我有SOAP Web服务,并尝试连接它。但SOAP响应包含“System.Xml.XmlException:缺少根元素”

我的obj-c代码。怎么了

NSString *soapMessage = [NSString stringWithFormat:
                         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                         "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
                         "<soap:Body>"
                         "<Method1 xmlns=\"http://tempuri.org/\">"
                         "<param1>string</param1>"
                         "</Method1>"
                         "</soap:Body>"
                         "</soap:Envelope>"];

NSLog(soapMessage);

NSURL *url = [NSURL URLWithString:@"web service url"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];


[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest addValue: @"\"http://tempuri.org/Method1\"" forHTTPHeaderField:@"SOAPAction"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if( theConnection )
{
    webData = [[NSMutableData data] retain];
}
else
{
    NSLog(@"theConnection is NULL");
}
NSString*soapMessage=[NSString stringWithFormat:
@""
""
""
""
“字符串”
""
""
""];
NSLog(soapMessage);
NSURL*url=[NSURL URLWithString:@“web服务url”];
NSMutableURLRequest*theRequest=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]];
[theRequest addValue:@“text/xml;charset=utf-8”用于HttpHeaderField:@“Content Type”];
[theRequest addValue:msgLength for HttpHeaderField:@“内容长度”];
[请求附加值:@“\”http://tempuri.org/Method1\“”forHTTPHeaderField:@“SOAPAction”];
[TheRequestSetHttpMethod:@“POST”];
[TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding];
NSURLConnection*连接=[[NSURLConnection alloc]initWithRequest:theRequest委托:self];
if(连接)
{
webData=[[NSMutableData]保留];
}
其他的
{
NSLog(@“连接为空”);
}
NSString*soapMessage=[NSString stringWithFormat:
@""
""
""
""
"%@"
""
""
“,str];
Str这里有一个字符串,需要传递给param1。
希望这对你有用。

您需要从以下位置删除额外的报价:

[theRequest addValue: @"\"http://tempuri.org/Method1\"" forHTTPHeaderField:@"SOAPAction"];
应改为:

[theRequest addValue: @"http://tempuri.org/Method1" forHTTPHeaderField:@"SOAPAction"];

希望有帮助。

我已经知道如何使用它了。我可能使用“字符串”伪代码。有什么建议吗?不幸的是,它没有帮助:(
[theRequest addValue: @"http://tempuri.org/Method1" forHTTPHeaderField:@"SOAPAction"];