java利用httpconnect向服务器发送信息与接收回馈信息

package com.cn;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class http {

/**
* @param args
*/
public static String url="http://192.168.0.172/hs/androids/report.php?un=1";
public static void main(String[] args) {
// TODO Auto-generated method stub
 String urls="http://127.0.0.1/hs/androids/report.php?un=野草我来过了";
try{
URL url=new URL(urls);
HttpURLConnection http=(HttpURLConnection)url.openConnection();
http.setDoInput(true);
http.setDoOutput(true);
http.setUseCaches(false);
 http.setRequestMethod("GET");
http.connect();

ObjectOutputStream osi = new ObjectOutputStream(http.getOutputStream());
String curlPost = "un=1" ;
osi.write(curlPost.getBytes("UTF-8"));
osi.flush();
osi.close();
String result="";
InputStream inStrm = http.getInputStream();
 BufferedReader in=new BufferedReader(new InputStreamReader(inStrm));
String inputLine;
while ((inputLine = in.readLine()) != null){
result = result.concat(inputLine);
}

System.out.println(result);
change(result);
in.close();

http.disconnect();
}catch (Exception e) {

System.out.println("err");
}

}
public static void change(String str)
{
Document dc=Jsoup.parse(str);
Elements em=dc.select("body");
em=em.select("div");
System.out.println(em.html());

}

}

 

 

 

 

返回结果

你可能感兴趣的:(connect)