import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class game1205{
public static void main(String[] args) {
String urlString = "http://www11.atpages.jp/ce00582/a1.php";
try {
URL url = new URL(urlString);
URLConnection uc = url.openConnection();
uc.setDoOutput(true);//POST可能にする
OutputStream os = uc.getOutputStream();//POST用のOutputStreamを取得
String postStr = "foo1=bar1&foo2=bar2";//POSTするデータ
PrintStream ps = new PrintStream(os);
ps.print(postStr);//データをPOSTする
ps.close();
InputStream is = uc.getInputStream();//POSTした結果を取得
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String s;
while ((s = reader.readLine()) != null) {
System.out.println(s);
}
reader.close();
} catch (MalformedURLException e) {
System.err.println("Invalid URL format: " + urlString);
System.exit(-1);
} catch (IOException e) {
System.err.println("Can't connect to " + urlString);
System.exit(-1);
}
}
}
最終更新:2011年02月10日 00:40