2015-04-05 76 views
0

我是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肥皂行動,但我無法稱呼它。

回答

0

集內容類型爲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]; 
}