Search code examples
objective-cnsurlrequest

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?


Solution

  • 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.