package com.jr.demo;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class C {
public static void main(String[] args) throws IOException {
URL url=new URL("http://pc201407240141:8080/Spring_MVC_Test/loging.html");
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.connect();
DataOutputStream outputStream=new DataOutputStream(connection.getOutputStream());
String content="name="+URLEncoder.encode("吕佳瑞", "gbk");
content+="&pwd="+URLEncoder.encode("123", "gbk");
outputStream.writeBytes(content);
outputStream.flush();
outputStream.close();
InputStreamReader is=new InputStreamReader(connection.getInputStream());
BufferedReader br=new BufferedReader(is);
String line="";
StringBuffer sb=new StringBuffer();
while ((line=br.readLine())!=null) {
sb.append(line);
}
System.out.println(sb.toString());
br.close();
}
}
时间: 2024-10-30 10:07:04