gpt4 book ai didi

iphone - 通过http post请求调用ios-Soap方法但响应为空

转载 作者:可可西里 更新时间:2023-11-01 04:53:35 25 4
gpt4 key购买 nike

xx我是 iPhone 新手。在我的应用程序 Soap 方法中使用导入和导出数据..虽然导入工作正常但导出不工作来自 soap Web 服务的响应是空的..

//参数

NSString *cust=@"<NEWCUSTOMERS><NEWCUSTOMER></NEWCUSTOMER></NEWCUSTOMERS>"; 
NSString *trans=@"<TRANS><TRAN></TRAN></TRANS>";
NSString *RETURNS=@"<RETURNS><RETURN></RETURN></RETURNS>";
NSString *prepayment=@"<PREPAYMENTS><PREPAYMENT></PREPAYMENT></PREPAYMENTS>";
NSString *receipt=@"<RECEIPTS><RECEIPT></RECEIPT></RECEIPTS>";
NSString *spcode1=@"BB";
NSString *companyShortName=@"Sample Company Limited";
NSString *companyCode=@"01";

// SOAP 网址:

    NSURL *url = [NSURL URLWithString:@"http://xxx.xxx.xxx.xx/SAAP/SOAP.asmx"];

//SOAP 方法:

    NSString *soapMsg=[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>"
"<PostXMLStr xmlns=\"http://tempuri.org/\">"
"<cust>%@</cust>"
"<tran>%@</tran>"
"<ret>%@</ret>"
"<ppay>%@</ppay>"
"<recp>%@</recp>"
"<sCode>%@</sCode>"
"<companyShortName>%@</companyShortName>"
"<companyCode>%@</companyCode>"
"</PostXMLStr>"
"</soap:Body>"
"</soap:Envelope>",cust,trans,RETURNS,prepayment,receipt,spcode1,companyShortName,companyCode];

NSMutableURLRequest *requests = [[NSMutableURLRequest alloc] initWithURL:url];
NSLog(@"soapMsg= %d soapMsg=%@",soapMsg.length,soapMsg);
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]];
NSLog(@"msgLength=%@ ",msgLength);

[requests addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[requests addValue:@"chunked" forHTTPHeaderField:@"transfer-coding"];
[requests addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[requests setValue:@"http://tempuri.org/PostXMLStr" forHTTPHeaderField:@"SOAPAction"];
[requests setHTTPMethod:@"POST"];

[requests setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
// [requests setHTTPBodyStream:dataStream];
//[requests setTimeoutInterval:2000];
NSLog(@"request=%@",requests);

NSURLResponse *response;
NSError *error = nil;

//强文本:

    NSMutableData   *data =[[NSMutableData alloc]init];
data =(NSMutableData *) [NSURLConnection sendSynchronousRequest:requests returningResponse:&response error:&error];

//[NSURLConnection connectionWithRequest:requests delegate:self];
//NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:requests delegate:self startImmediately:YES];
//NSURLConnection *connection=[NSURLConnection connectionWithRequest:requests delegate:self];


NSLog(@"requestdata=%@",data);
stringSoap = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSDictionary *headers = [(NSHTTPURLResponse *)response allHeaderFields];
NSLog(@"data %@",headers);
NSLog(@"error %@ data str %@ resulString=%@",error,stringSoap,resulString);

//soap方法的结果:有数据str为空响应..

 soapMsg=<?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><PostXMLStr xmlns="http://tempuri.org/"><cust><NEWCUSTOMERS><NEWCUSTOMER></NEWCUSTOMER></NEWCUSTOMERS></cust><tran><TRANS><TRAN></TRAN></TRANS></tran><ret><RETURNS><RETURN></RETURN></RETURNS></ret><ppay><PREPAYMENTS><PREPAYMENT></PREPAYMENT></PREPAYMENTS></ppay><recp><RECEIPTS><RECEIPT></RECEIPT></RECEIPTS></recp><sCode>BB</sCode><companyShortName>Sample Company Limited</companyShortName><companyCode>01</companyCode></PostXMLStr></soap:Body></soap:Envelope>
2013-03-18 14:27:05.151 MSP[6940:207] msgLength=679
2013-03-18 14:27:05.152 MSP[6940:207] request=<NSMutableURLRequest http://xx.xxx.xxx.xx/SAAP/SOAP.asmx>
2013-03-18 14:27:05.410 MSP[6940:207] requestdata=<>
2013-03-18 14:27:05.411 MSP[6940:207] data {
"Cache-Control" = private;
"Content-Length" = 0;
Date = "Mon, 18 Mar 2013 08:59:16 GMT";
Server = "Microsoft-IIS/5.1";
"X-AspNet-Version" = "2.0.50727";
"X-Powered-By" = "ASP.NET";
}
2013-03-18 14:27:05.412 MSP[6940:207] error (null) data str resulString=(null)

请帮帮我...

最佳答案

是否有可能您的 Transfer-Coding:chunked header 混淆了服务器,因此它无法处理您的数据?你知道 Content-Length 所以显然没有必要以 block 的形式发送数据,而且我认为无论如何你都不能用 NSURLConnection 来做到这一点。

关于iphone - 通过http post请求调用ios-Soap方法但响应为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15472859/

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