http://www.enseignement.polytechnique.fr/informatique/profs/Laurent.Viennot/majReseau/2006-2007/td2/index.html
import java.net.*;
import java.io.*;
public class PostHTTPGet {
public static void main(String[] args) {
try {
//Create socket
String hostname = "ws.cdyne.com";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket sock = new Socket(addr, port);
//System.out.println("Connected");
//Send data
OutputStream theOutput = sock.getOutputStream();
PrintWriter pw = new PrintWriter(theOutput, false);
String file = "/";
pw.println("GET " + file + " HTTP/1.0");
//pw.println("Accept: text/plain, text/html, text/*");
pw.println();
pw.flush();
//wr.write("GET /WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=55416 HTTP/1.1\r\n");
//wr.write("Host: ws.cdyne.com\r\n");
// Response
BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String line;
while((line = rd.readLine()) != null)
System.out.println(line);
//wr.close();
//br.close();
} catch (Exception e) {
//System.out.println("Usage: java TestHost www.igbmc.fr");
e.printStackTrace();
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment