NSString *GetExRequest=[NSString stringWithFormat:
@"<?xmlversion=\"1.0\"encoding=\"utf-8\"?>\n"
"<soap:Envelopexmlns:xsi=\"http://www.w3.org/2001/XMLSchemainstance\"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soap:Body>\n"
"<GetEXRatexmlns=\"Web Services\">\n"
"<AGENT_CODE>xyzzyx</AGENT_CODE>\n"
"<USER_ID>12345689</USER_ID>\n"
"<PASSWORD>dkasdja</PASSWORD>\n"
"<AGENT_SESSION_ID>xyz1234</AGENT_SESSION_ID>\n"
"<TRANSFERAMOUNT>1000</TRANSFERAMOUNT>\n"
"<PAYMENTMODE>c</PAYMENTMODE>\n"
"<CALC_BY>p</CALC_BY>\n"
"<PAYOUT_AGENT_ID>20100008</PAYOUT_AGENT_ID>\n"
"<PAYOUT_COUNTRY>Bangladesh</PAYOUT_COUNTRY>\n"
"</GetEXRate>\n"
"</soap:Body>\n"
"</soap:Envelope>\n"];
NSLog(@"%@",GetExRequest);
NSURL *url = [NSURL URLWithString:@"https://www.prabhuusa.com/SendWsv2/txnservice.asmx?wsdl"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [GetExRequest length]];
[theRequest addValue:@"www.prabhuusa.com" forHTTPHeaderField:@"Host"];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"WebServices/GetEXRate" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [GetExRequest dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
我正在尝试通过发送此 SOAP 请求来使用此 WSDL 定义。我想将响应存储到一个字符串并解析它。
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [_webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [_webData mutableBytes] length:[_webData length] encoding:NSUTF8StringEncoding];
NSLog(@"WEBDATA::: %@",theXML);
}
但是响应字符串是空白的。我用我使用 SOAP 客户端发送的 SOAP 请求检查了这个 web 服务,并收到了一个 XML 响应。但我无法在目标 C 中得到响应。请给我一个解决方案
我的 didRecieveResponse 和 didRecieveData 方法中有这个
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[_webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[_webData appendData:data];
}