0

I am trying to fill up a web form and submit data without letting the user see the web form itself. I have tried using AFNetworking to do HTTP POST in the background, but I bumped into a problem which I couldn't solve and decided to try something else.

This time, I have a UIWebView which is hidden in the background. I then edit the text in the respective fields using Javascript in the webViewDidFinishLoad:webView as follows:

NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:nameField.text     forKey:@"name"];
[params setObject:emailField.text    forKey:@"email"];
[params setObject:titleField.text    forKey:@"title"];
[params setObject:dateString         forKey:@"link"];
[params setObject:descriptionTV.text forKey:@"content"];
[params setObject:tag                forKey:@"tags"];

[params enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
    NSLog(@"%@ = %@", key, object);
    NSString *javascriptString = [NSString stringWithFormat:@"document.getElementById('%@').value = '%@'",key,object];
    [webView stringByEvaluatingJavaScriptFromString:javascriptString];
}];

Is there any way I could do the same, but for uploading images/files?

Community
  • 1
  • 1
Jian Jie
  • 289
  • 1
  • 2
  • 13

1 Answers1

0

You should use an NSHTTPRequest to POST the image to the form directly. There is no need to use a UIWebView, hidden or otherwise. See this answer for an example of how to implement this. Here is another example of this.

Community
  • 1
  • 1
Tim
  • 14,447
  • 6
  • 40
  • 63