0
我正在嘗試將XML數據發送到Web服務。但我沒有收到任何服務的迴應。當我試圖通過SOAPUI發送XML ...我得到了錯誤的「傳入參數failiure」 ..任何一個可以請檢查我的代碼,並指出我什麼我做錯了..在ios應用程序中訪問Web服務
- (void)viewDidLoad
{
NSString *Message = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<SOAP-ENV:Envelope \n"
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
"xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n"
"<SOAP-ENV:Body> \n"
"<XMLGetReportParameters xmlns=\"http://PlusDiagnostics.Schemas.GetReportParameters\"><UserName xmlns="">USERNAME</UserName><Password xmlns="">PASSWORD</Password><List xmlns="">All</List></XMLGetReportParameters>"
"</SOAP-ENV:Body> \n"
"</SOAP-ENV:Envelope>" ];
NSURL *url = [NSURL URLWithString:@"https://pathflexstage.plusdx.com/MobileReporting/GetPathologyReports.svc"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [Message length]];
NSLog(@"message length is %d",[Message length]);
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest addValue: @"http://tempuri.org/IGetPathologyReports/GetReports" forHTTPHeaderField:@"soapAction"];
[theRequest setHTTPBody: [Message dataUsingEncoding:NSUTF8StringEncoding]];
NSString *returnString = [[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil] encoding:NSUTF8StringEncoding];
// NSLog("return");
NSLog(@"%@",returnString);
[super viewDidLoad];
}
您可能想要從代碼中刪除密碼。您是否嘗試過在桌面瀏覽器中將XML發送到服務器?像擴展名爲Poster的Firefox一樣? –
我不同意這個被關閉,當我正在學習如何通過iphone/objective-c訪問web服務時,它會真的幫助我 – AnthonyBlake