iphone - 服务器无法识别 iPhone 中 HTTP header SOAPAction 的值?

标签 iphone ios

我正在尝试将 web 服务连接到我的代码,但出现错误

"Server did not recognize the value of HTTP Header SOAPAction"

NSString *soapMessage = [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"
                         "<Hello xmlns=\"http://viium.com/\">\n"
                         "<name>%@</name>\n"
                         "</Hello>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>\n", @"new"
                         ];
NSLog(soapMessage);

NSURL *url = [NSURL URLWithString:@"http://viium.com/WebService/HelloWorld.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

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

请指导我缺少什么?

最佳答案

NSURL *url = [NSURL URLWithString:@"https://servername.com/WebService/WebServicename.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMessage length]];
[theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"servername.com/Hello" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection  *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

这是链接,

http://abhicodehelp.blogspot.com/2010/12/handling-soap-with-iphone.html

这可能对你有帮助..

关于iphone - 服务器无法识别 iPhone 中 HTTP header SOAPAction 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3290302/

相关文章:

iOS:自定义辅助触摸菜单并在顶级菜单中添加我的应用程序启动器

ios - Swift-无法使用 SpriteKit 呈现 Game Center

ios - SwiftUI 以异步方式加载很长的列表

iphone - 在 Xcode 中使用 stricmp 时出现构建错误

ios - 在没有动画的情况下隐藏 viewDidLoad 中的后退按钮

objective-c - Objective C IOS - 根据 slider 的值转换为特定字符串

c# 如何通过网页 (Safari) 在 iPAD 或 iPhone 上访问网络摄像头和麦克风

ios - 适用于 iOS 的 Qt : Error unknown module(s) in Qt: webkitwidgets

ios - Swift:使用带有多个参数的选择器

ios - Apple Watch 是否可以直接从 Web 服务器获取数据,而无需 iPhone 作为中介?