HTTP URLConnection sends get request

    String urlstr="servie="+URLEncoder.encode(serivce,"UTF-8") +"&partener="+URLEncoder.encode(partener,"UTF-8");

    String newUrl="http://10.53.78.116:80/gateway.do?"+urlstr;

    URL realUrl = new URL (newUrl);

    URLConnection connect=realUrl.openConnection();

    //Set the request timeout

    connection.setConnectionTimeOut(6000);

    //Set the general request attribute header

    connection.setRequestProperty("accept","*/*");

    connection.setRequestProperty("connection","Keep-Alive");

    connection.setRequestProperty("user-agent","Mozilla/4.0(compatiable;MSIE 6.0; Windows NT 5.1; sv1)");

    connection.connect();

   //Set the response timeout

   connection.setReadTime(6000);

   // get all response header fields

    Map<String,List<String>> map= connection.getHeaderFields();

    for(String key :map.keySet()){

         system,out.println(map.getKey(key));

       }

if(conn.getResponseCode()==200){//Prove that the transmission was successful

                     return true;

           }

    //Define the bufferedReader character stream to read the response of the URL
    BufferedReader bred=new BufferedReader(new InputStreamReader(connection.getInputStream()));

    String line="";

   while((line=bred.readLine()) !=null){

       str+=line

      }

   syso....(str);

 

   close stream

    bred.close();

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325938585&siteId=291194637