Thizzer
Thizzer

Reputation: 16653

Get POST parameter from NSURLRequest

Is it possible to retrieve the value of a POST parameter from a NSURLRequest in the method;

-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

Is so, how is this done?

Upvotes: 4

Views: 7297

Answers (2)

Spencer Hall
Spencer Hall

Reputation: 3739

    NSURLRequest *request = ...
    NSError *error = nil;
    NSDictionary *parameters = [NSJSONSerialization JSONObjectWithData:[request HTTPBody] options:0 error:&error];

Upvotes: 0

das_weezul
das_weezul

Reputation: 6142

That should be possible with the class method of NSURLProtocol:

+ (id)propertyForKey:(NSString *)key inRequest:(NSURLRequest *)request

So if you have got a property named "place" you could try that:

[NSURLProtocol propertyForKey:@"place" inRequest:myRequestObject]

[EDIT] If you want to retrieve all properties, I think you have to use - (NSData *)HTTPBody from NSURLRequest and then parse the property names/values yourself. Should be no problem with urldecode and RegEx.

Upvotes: 3

Related Questions