URL url=new URL("http://10.0.2.2:8080/LoginTest/servlet/LoginServlet?username="+URLEncoder.encode("zhangsan")+"&password=123");
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");//设置方法
connection.connect();//连接
if(connection.getResponseCode()==200){
InputStream is = connection.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader bf=new BufferedReader(isr);
ByteArrayOutputStream bos=new ByteArrayOutputStream();
byte[] by=new byte[1024];
int len=0;
while((len=is.read(by))!=-1){
bos.write(by, 0, len);
}
connect = new String(bos.toByteArray(),"utf-8");
}
HttpURLConnection connection=(HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");//设置方法
connection.connect();//连接
if(connection.getResponseCode()==200){
InputStream is = connection.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader bf=new BufferedReader(isr);
ByteArrayOutputStream bos=new ByteArrayOutputStream();
byte[] by=new byte[1024];
int len=0;
while((len=is.read(by))!=-1){
bos.write(by, 0, len);
}
connect = new String(bos.toByteArray(),"utf-8");
}