Reputation: 10398
I have a html form which when it loads is already populated with data. It has Save and Apply buttons on.
I want to change 1 item on the form and POST it from my iOS app. The problem is that when I send the POST with my changed Form Data info for the item i'm changing, I also need to submit all the other current settings from the form or they get overwritten with blanks. (I have no control over editing the page).
I could parse the page beforehand to grab the displayed data from the form then send it with the POST, however the page can appear different for each user so this will be very difficult.
In a web browser when I hit the Save button after loading the page, I can see all the POST headers and form data, so I'm thinking I can do this in my app to grab the current data then amend the 1 item I wish to change, then rePOST it.
So my question is, if I read a page with AFNetworking, can I then simulate pressing the Save button on that page, so I can then read the response but this time with the POST and header data?
Or any alternative thought on how to achieve this?
Upvotes: 3
Views: 502
Reputation: 492
This might work by accessing the Document Object Model... check the syntax...
NSString *formValue = [webView stringByEvaluatingJavaScriptFromString
:@"document.forms[0].elements[0].value"];
//...change value...
NSString *jScript = [NSString stringWithFormat
:@"document.forms[0].elements[0].value='%@';", formValue ];
[webView stringByEvaluatingJavaScriptFromString: jScript ];
[webView stringByEvaluatingJavaScriptFromString: @"document.forms[0].submit();"];
Upvotes: 5