http://ws.cdyne.com//WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=55416
--------------------------------------------------------------------

--------------------------------------------------------------------------
import java.net.*;
import java.io.*;
public class PostHTTPPost {
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");
String postdata = "ZIP" + "=" + URLEncoder.encode("55416", "UTF-8");
//System.out.println("length: " + postdata.length());
// Send header
String path = "//WeatherWS/Weather.asmx/GetCityWeatherByZIP";
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF8"));
bw.write("POST " + path + " HTTP/1.0\r\n");
bw.write("Content-Length: " + postdata.length() + "\r\n");
bw.write("Content-Type: application/x-www-form-urlencoded\r\n");
bw.write("\r\n");
// Send POST data string
bw.write(postdata);
bw.flush();
// 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();
}
}
}
---------------------------------------------------------------------------
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 = "/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=55416";
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();
}
}
}
-------------------------------------------------------------------------------
import java.net.*;
import java.io.*;
public class PostHTTPSOAP11 {
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");
String xmldata = "" +
"
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"
"
"
"
"
"";
//System.out.println("length: " + postdata.length());
// Send header
String path = "//WeatherWS/Weather.asmx";
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(), "UTF8"));
bw.write("POST " + path + " HTTP/1.0\r\n");
bw.write("Host: ws.cdyne.com\r\n");
bw.write("Content-Length: " + xmldata.length() + "\r\n");
bw.write("Content-Type: text/xml; charset=utf-8\r\n");
bw.write("\r\n");
// Send data
bw.write(xmldata);
bw.flush();
// 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();
}
}
}
No comments:
Post a Comment