gpt4 book ai didi

objective-c - 从 Objective c 到 asmx Web 服务的参数为空白

转载 作者:行者123 更新时间:2023-12-03 17:25:26 25 4
gpt4 key购买 nike

我正在从我的 xcode 调试器调用 .Net asmx Web 服务。在调试器中,我可以看到我正在传递一些值,但在 .net Web 服务上它是空白的。

在网络服务端,我正在写入日志文件。我看到该方法正在被调用,但参数为空/空。我已经粘贴了下面的代码。我也粘贴了wsdl。参数显示为空白的任何原因

-(void) fetchData: (NSString*)userid 
{
NSString *requestSoapMsg =
[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">\n"
"<soap:Body>\n"
"<UpdateRegForUser xmlns=\"http://soft.com\">\n"
"<userid>%@</userid>\n"
"</UpdateRegForUser>\n"
"</soap:Body>\n"
"</soap:Envelope>\n", userid];

NSLog(@"%@", requestSoapMsg); // i can see the value here

NSURL *url = [NSURL URLWithString:@"http://soft.com:8000/services/registration.asmx"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

NSString *requestSoapMsgLength = [NSString stringWithFormat:@"%d", [requestSoapMsg length]];
[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"http://soft.com/UpdateRegForUser" forHTTPHeaderField:@"SOAPAction"];
[request addValue:requestSoapMsgLength forHTTPHeaderField:@"Content-Length"];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:[requestSoapMsg dataUsingEncoding:NSUTF8StringEncoding]];

NSError *error;
NSURLResponse *response;

NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

if(!result)
NSLog(@"FAILEDDDDDDDDD!!");

WSDL -

POST /services/registration.asmx HTTP/1.1

Host: soft.com


Content-Type: text/xml; charset=utf-8

Content-Length: length

SOAPAction: "http://soft.com/UpdateRegForUser"

<?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>
<UpdateRegForUser xmlns="http://soft.com/">
<userid>string</userid>
</UpdateRegForUser>
</soap:Body>
</soap:Envelope>

最佳答案

我发现了问题所在。

我编写了一个 C# 控制台应用程序并调用了 Web 服务。同时,我捕获了 fiddler 的痕迹。 fiddler 跟踪显示 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"应该出现在 xsi 之前。我保存了 xml 并使我的请求 xml 完全相同。它开始工作了。

关于objective-c - 从 Objective c 到 asmx Web 服务的参数为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6516709/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com