Skip to content

Send POST request to GSA CB with Java

Hey.
I'm using this GSA CB with Java.
And i trying to use HttpURLConnection to send a POST request to http://127.0.0.1:80/gsa_test.gsa and hope to get response with String like 

The solution is :: hyby7.


Following is my code:

private void sendPost() throws Exception {
 
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");
 
              "captcha_plattform=any";
 
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
 
int responseCode = con.getResponseCode();
System.out.println("Sending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
 
//get Response
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
 
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
 
//print result
System.out.println(response);
 
}

I suppose i should get answer at response.
But the response is always empty.
I do receive responseCode=200 by con.getResponseCode();
Did i missing any parameter or else.

Thx for helping.
Best regards.

Comments

  • s4nt0ss4nt0s Houston, Texas
    edited October 2013
    I would help but I don't know anything about Java, but if you type @sven it will summon the coding god.
  • SvenSven www.GSA-Online.de
    source_url is just an extra that is used inside CB to show where the captcha from. You can not use it to hold the actual captcha content. You have to use the actual file input variable to send the captcha image. You can also use the de-captcha api itself and exchange the host with 127.0.0.1 ... maybe thats easier for you as Im sure there exists apis for decaptcha using java.
Sign In or Register to comment.