5

xxiPhone 初心者です。私のアプリでは、データのインポートとエクスポートに使用する Soap メソッド。

//パラメーター

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";

// 石鹸の URL:

    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 メソッドの結果: data str is empty response..

 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)

私を助けてください...

4

1 に答える 1

1

Transfer-Coding:chunkedヘッダーがサーバーを混乱させ、その結果、データを処理できない可能性はありますか? を知っているので、明らかにデータをチャンクで送信する必要はありません。 とにかくContent-Lengthでそれを行うことはできないと思います。NSURLConnection

于 2013-05-04T02:31:43.057 に答える