It is necessary to use the ruCaptha service for captcha recognition. Description API on their website.
In short, they need to POST request to send a picture encoded in base64 and then in URLEncode.
When it is done like this
String url = "http://rucaptcha.com/in.php"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", USER_AGENT); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = "method=base64&key=*****************&"+"body="+img+"&submit=загрузить и получить ID"; // Send post request con.setDoOutput(true); try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) { wr.writeBytes(urlParameters); wr.flush(); } StringBuffer response; try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) { String inputLine; response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } } resp = response.toString(); resp_code = resp.substring(3); System.out.println("ID заказа : "+resp_code); That all works. But you need to do this with Apache HTTP Client 4.5.2. Wrote such code
HttpPost httpPost = new HttpPost("http://rucaptcha.com/in.php"); java.util.List <NameValuePair> nvps = new ArrayList <NameValuePair>(); nvps.add(new BasicNameValuePair("method", "base64")); nvps.add(new BasicNameValuePair("key", "***********")); nvps.add(new BasicNameValuePair("body", img)); nvps.add(new BasicNameValuePair("submit", "загрузить и получить ID")); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); httpPost.setConfig(config); CloseableHttpResponse response = httpClient.execute(httpPost); String entityString = EntityUtils.toString(response.getEntity()); System.out.println(entityString); resp_code = entityString.substring(3); //System.out.println(resp); System.out.println("ID заказа : "+resp_code); EntityUtils.consume(response.getEntity()); But I get the error ERROR_IMAGE_TYPE_NOT_SUPPORTED. Googling understood that you need to send POST type multipart / form-data. But how to do it specifically in this situation?
imgvariable contains the value encoded in base64 + url-encode, but it should just be base64 (apache httpclient itself makes url-encode). - Roman