Saturday, 14 September 2013

NSURConnection GET REQUEST

NSURConnection GET REQUEST

I came across NSURLConnection, I used it before, simply on request, and
getting data and parsing it. However this time web developer has developed
GET and POST requests.
I want through many tutorials and stack question and tried to get desired
result. As I see there is sometime request, like this
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL
URLWithString:@"URL"]
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:10];
[request setHTTPMethod: @"GET"];
NSError *requestError;
NSURLResponse *urlResponse = nil;
NSData *response1 = [NSURLConnection sendSynchronousRequest:request
returningResponse:&urlResponse error:&requestError];
also few others I have seen.
I looks easy but I am unable to find what is required for any POST and GET
request.
The data which I have received from my web developer is
SOAP 1.2
POST /DEMOService/DEMO.asmx HTTP/1.1
Host: projects.demosite.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
and in return there will be GET and POST
The following is a sample HTTP GET request and response. The placeholders
shown need to be replaced with actual values.
GET
/DEMOService/DEMO.asmx/VerifyLogin?username=string&password=string&AuthenticationKey=string
HTTP/1.1
Host: projects.demosite.com
I am well-aware of delegates of NSURLConnections, which are following..
#pragma mark NSURLConnection Delegate Methods
- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response {
// A response has been received, this is where we initialize the instance
var you created
// so that we can append data to it in the didReceiveData method
// Furthermore, this method is called each time there is a redirect so
reinitializing it
// also serves to clear it
_responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData
*)data {
// Append the new data to the instance variable you declared
[_responseData appendData:data];
}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
willCacheResponse:(NSCachedURLResponse*)cachedResponse {
// Return nil to indicate not necessary to store a cached response for
this connection
return nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// The request is complete and data has been received
// You can parse the stuff in your instance variable now
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError
*)error {
// The request has failed for some reason!
// Check the error var
}
THE ONLY THING WHERE I AM STUCK IS
How to write request where I have pass arguments, in GET or POST request.
Thanks

No comments:

Post a Comment