SOAP web API请求返回HTML而不是XML
问题描述:
我是SOAP API的新手。SOAP web API请求返回HTML而不是XML
我正在使用下面的代码来访问我的API。
NSString *stringURL=[NSString stringWithFormat:@"http://tennispro.co.in/services.asmx"];
// Allocate and initialize an NSURLConnection with the given request and delegate. The asynchronous URL load process is started as part of this method.
NSString *soapMessage = [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>"
"<ReturnSyncMasterData xmlns=\"http://tempuri.org/\">"
"<datetime>%@</datetime>"
"</ReturnSyncMasterData>"
"</soap:Body>"
"</soap:Envelope>",@""];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:stringURL]];
[request addValue:@"text/html; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"2159" forHTTPHeaderField:@"Content-Length"];
[request addValue:@"private, max-age=0" forHTTPHeaderField:@"Cache-Control"];
[request addValue:@"gzip" forHTTPHeaderField:@"Content-Encoding"];
[request addValue:@"http://tempuri.org/services/ReturnSyncMasterData" forHTTPHeaderField:@"SOAPAction"];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];
theConnection = [NSURLConnection connectionWithRequest:request delegate:self];
if (theConnection) {
receivedData = [[NSMutableData alloc] init];
}
但作为回应,我得到的是HTML而不是XML。我想访问ReturnSyncMasterData
肥皂行动,但我无法称呼它。
答
集内容类型为text/xml
[request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"2159" forHTTPHeaderField:@"Content-Length"];
[request addValue:@"private, max-age=0" forHTTPHeaderField:@"Cache-Control"];
[request addValue:@"gzip" forHTTPHeaderField:@"Content-Encoding"];
[request addValue:@"http://tempuri.org/services/ReturnSyncMasterData" forHTTPHeaderField:@"SOAPAction"];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPMethod:@"POST"];
theConnection = [NSURLConnection connectionWithRequest:request delegate:self];
if (theConnection) {
receivedData = [[NSMutableData alloc] init];
}