【发布时间】:2010-12-20 06:06:07
【问题描述】:
我是 iphone 网络服务的新手。
我不喜欢这个tutorial
我的代码是休闲的
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>"
"<GenericAndroidMethod xmlns=\"Mortgage\">"
"<methodName>MortgageGetLoanOfficerInfo</methodName>"
"<xmlParam><MortgageGetLoanOfficerInfo><PhoneNumber>919703661366</PhoneNumber></MortgageGetLoanOfficerInfo></xmlParam>"
"</GenericAndroidMethod>"
"</soap:Body>"
"</soap:Envelope>"
];
NSLog(@"%@",soapMsg);
NSURL *url = [NSURL URLWithString:@"http://10.10.8.7/MobileGenericWebservice/GenericWebService.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8"
forHTTPHeaderField:@"Content-Type"];
[req addValue:@"Mortgage/GenericAndroidMethod"forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength
forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn) {
NSLog(@"connected %@",conn);
webData = [[NSMutableData data] retain];
}
}
-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response {
NSLog(@"connect %@",connection);
[webData setLength: 0];
}
-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data {
NSLog(@"test %@",data);
[webData appendData:data];
}
-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error {
NSLog(@"error will occer %@",error);
[webData release];
[connection release];
}
-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSLog(@"recived data %@",webData);
NSString *theXML = [[NSString alloc]
initWithBytes: [webData mutableBytes]
length:[webData length]
encoding:NSUTF8StringEncoding];
//---shows the XML---
NSLog(@"%@",theXML);
[theXML release];
[connection release];
[webData release];
}
在控制台中我得到了
2010-12-20 11:23:50.754 Hello_SOAP[1911:40b] <?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><GenericAndroidMethod xmlns="Mortgage"><methodName>MortgageGetLoanOfficerInfo</methodName><xmlParam><MortgageGetLoanOfficerInfo><PhoneNumber>919703661366</PhoneNumber></MortgageGetLoanOfficerInfo></xmlParam></GenericAndroidMethod></soap:Body></soap:Envelope>
2010-12-20 11:23:50.963 Hello_SOAP[1911:40b] connected <NSURLConnection: 0x5d3dc30, http://10.10.8.7/MobileGenericWebservice/GenericWebService.asmx>
2010-12-20 11:23:51.375 Hello_SOAP[1911:40b] connect <NSURLConnection: 0x5d3dc30, http://10.10.8.7/MobileGenericWebservice/GenericWebService.asmx>
2010-12-20 11:23:51.376 Hello_SOAP[1911:40b] DONE. Received Bytes: 0
2010-12-20 11:23:51.377 Hello_SOAP[1911:40b] recived data <>
在连接 didReceiveData 时我没有得到任何数据
谁能帮我解释一下为什么我没有收到数据。
提前谢谢你。
【问题讨论】:
-
抱歉,工作量太大,阅读所有代码并试图弄清楚。你能缩小问题的范围,确切地解释哪里有问题吗?
标签: iphone