I am trying to send a post request to a site using the Echo 3.0 web framework. My goal is to log into the site using a post request. I have looked at the requests using firebug, and can see that the website expects a post request in the following format:
<cmsg xmlns="http://ift.tt/1wM7YzP" i="1">
<dir xmlns="" proc="CFocus">
<focus i="C.21"></focus>
</dir>
<dir xmlns="" proc="CSync">
<e t="action" i="C.21"></e>
<p i="C.19" n="selectionStart">5</p>
<p i="C.19" n="selectionEnd">5</p>
<p i="C.19" n="text">username</p>
<p i="C.20" n="selectionStart">10</p>
<p i="C.20" n="selectionEnd">10</p>
<p i="C.20" n="text">password</p>
</dir>
</cmsg>
Firebug can also tell me that i'm supposed to receive an xml response. The issue is that I instead receive the source code of the page i've sent the request to.
This is the code I am currently using to send the post request.
NSString *urlString = [NSString stringWithFormat:@"http://147.29.29.224"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
//set headers
NSString *contentType = [NSString stringWithFormat:@"text/xml; charset=UTF-8"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSString *xmlString = @"<cmsg xmlns='http://ift.tt/1wM7YzP' i='1'><dir xmlns='' proc='CFocus'><focus i='C.21'></focus></dir><dir xmlns='' proc='CSync'><e t='action' i='C.21'></e><p i='C.19' n='selectionStart'>5</p><p i='C.19' n='selectionEnd'>5</p><p i='C.19' n='text'>username</p><p i='C.20' n='selectionStart'>10</p><p i='C.20' n='selectionEnd'>10</p><p i='C.20' n='text'>password</p></dir></cmsg>";
[request setValue:[NSString stringWithFormat:@"%lu",
(unsigned long)[xmlString length]]
forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[xmlString
dataUsingEncoding:NSUTF8StringEncoding]];
//create the body
//get response
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"Response Code: %ld", (long)[urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
NSLog(@"Response: %@", result);
//here you get the response
}
The code gives me a response code of 200.
What am i doing wrong? Am i send the post request to the wrong page?
No comments:
Post a Comment