How do I get the same browser answer using java/socket?

Asked

Viewed 282 times

0

The thing is, someone already had to make a request http-post implementing socket java?

I need to make a request on the site http://spys.ru/en/ and take the Sponse to mine some proxys. However, I can’t bring the same Sponse that I get with me on Chrome or with the gabiroto, always comes a gap of information!.

Remembering that the requirement is to use SOCKET I mean, I can’t use any derivative of this guy, even if he uses socket.

try {
        // Construct data
        String data = URLEncoder
                .encode("tldc=0&eport=8080&anmm=0&vlast=0&submit=Proxy+search",
                        "UTF-8");

        s = new Socket("spys.ru", 80);

        // Send headers
        wr = new BufferedWriter(new OutputStreamWriter(s.getOutputStream(),
                "UTF8"));
        wr.write("POST /en/ HTTP/1.0\r\n");

        wr.write("Host: spys.ru\r\n");
        wr.write("Connection: keep-alive\r\n");
        wr.write("Content-Length: " + data.length() + "\r\n");
        wr.write("Cache-Control: max-age=0\r\n");
        wr.write("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n");
        wr.write("Origin: http://spys.ru\r\n");
        wr.write("User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36\r\n");
        wr.write("Content-Type: application/x-www-form-urlencoded\r\n");
        wr.write("Referer: http://spys.ru/en/\r\n");
        wr.write("Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4\r\n");

        wr.write("\r\n");

        // Send parameters
        wr.write(data);
        wr.flush();

        // Get response
        rd = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String line;



        while ((line = rd.readLine()) != null) {
            System.out.println(line);                           
        }

    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            s.close();
            wr.close();
            rd.close();
        } catch (IOException e) {

        }
    }
}
  • Apparently the fields are correct. What is being returned? What may be giving problem is you not using chunked when receiving the data (I did not test whether it works at HTTP 1.0).

  • I just tested here, even without setting any of the headers, came the whole list, on line 101 or 102 of HTML. PS: I did not test in java, I used another language. But all data comes smoothly, without any juggling.

  • The following is, I need to give a "proxy search" and pass the post parameters. So I think I’m going to need to get this page, store the cookie and then send a post with the parameters.

  • You didn’t need any of that here, I just made the requisition with tldc=0&eport=8080&anmm=0&vlast=0&submit=Proxy+search and the results came smoothly. I didn’t even have to simulate the browser headers.

  • Are you sure you are analyzing the return correctly?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.