I am trying to fetch xml using NSMutableRequest and NSURL connection but I am receiving 0 bytes but when I passed ?WSDL in the link so in response get the schema, but I want to fetch xml and then will parse using TouchXML. My code below.
NSString *username = @"username";
NSString *password = @"pasword";
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<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/\">\n"
"<soap:Header>\n"
"<RequestAuthenticator xmlns=\"http://tempuri.org/\">\n"
"<Password>%@</Password>\n"
"<UserName>%@</UserName>\n"
"</RequestAuthenticator>\n"
"</soap:Header>\n"
"<soap:Body>\n"
"<METHODNAME xmlns=\"http://tempuri.org/\"/>\n"
"</soap:Body>\n</soap:Envelope>\n",password,username];
NSLog(@"%@",soapMessage);
NSURL *url = [NSURL URLWithString:@"http://websitename.com/website_english/wservice/website_service.asmx"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
/*ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setUseKeychainPersistence:YES];
[request setUsername:@"username"];
[request setPassword:@"password"];
[request setDelegate:self];
[request startAsynchronous];*/
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request addValue: @"http://tempuri.org/METHODNAME" forHTTPHeaderField:@"SOAPAction"];
[request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with theConenction");
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",theXML);
[theXML release];
}
But it is returning me 0 bytes and no xml, original website name is not disclose for security.
I also tried HelloSOAP.xcodeproj sample code aswell but I am unable to get through it.