It is as follows, has anyone ever had to make a request http-post
implementing socket
in java?
I need to make a request on the site http://spys.ru/en/
and get the response to mine some proxys. However, I can not bring the same response that I get in chrome or gabiroto, it always comes with gap
/ p>
Remembering that the requirement is to use SOCKET
that is, I can not use any derivatives of this face, even if it 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) {
}
}
}