0

Good evening. In my application I need to send a request to a web page that needs a captcha. The image link is a .php and the captcha change every time I refresh the page. So, if I try to download the image "by link", I have a different captcha. What is the solution? Any idea? Thank you in advance.

EDIT: Now I have to fill the input and send the request to submit. This is the html source of textfields I have to fill:

<label class="ins" for="targ">Targa del veicolo:</label>
<input id="targ" name="targa" value="" type="text" size="20" maxlength="8" tabindex="2" />

<label for="inCaptchaChars">Codice di sicurezza:</label>  <input type="text" id="inCaptchaChars" name="inCaptchaChars" tabindex="1004" onblur="ShutMeDown()">

And this is about the submit button:

<input type="submit" name="procedi"  value="Calcola importo" />

What I have to do to proceed? I have to use ASIHTTP?

charles
  • 713
  • 1
  • 6
  • 16
  • Can you clarify, you are trying to snag the same captcha every time, irrespective of the random one the script gives you? – Chris Sep 01 '12 at 18:12
  • No, perhaps I wasn't clear enough. So.. If I send a request to load the webpage, the webpage needs a captcha (i.e. CAPTCHA1). Then I have to send a request to download the captcha, but when I re-send the request the captcha changed. I need to send the two request (load the page and download the image) in only one request. – charles Sep 01 '12 at 18:19

1 Answers1

1

This might be a little convoluted, but it should work alright:

Use a webView, load the page, when the page loaded call some javascript on the webview (stringByEvaluatingJavascript) that gets the image size and offset. Resize the WebView frame to that size, and scroll the content to that offset. Disable user interaction and show the webview. To get the element offset you can use this answer

Simply call:

[[webView stringByEvaluatingJavascript:@"function getOffset(el) {  .....  }  getOffset( document.getElementById('yourElId') ).left;"] floatValue];

not that you must pass the whole code to this method

To submit the captcha: As before, call

[webView stringByEvaluatingJavascript :@"document.getElementsByName('procedi')[0].value = 'your captcha';"];

then do the same to call .click() on the submit button or .submit() on the form

Community
  • 1
  • 1
andreamazz
  • 4,256
  • 1
  • 20
  • 36