少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

package com.abin.lii.han.limei;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import org.junit.Test;

public class ImediaRegisterTest {
 @Test
 public void testImediaRegister(){
  String LIMEI_HTTP="http://192.168.3.15:1000/release/mybe";
  String appId="fk000";
  String udid="3A5S4D6F8G9K_3596140444464123";
  String requestUrl=LIMEI_HTTP+"?app="+appId+"&udid="+udid+"&source="+"where"";
  System.out.println(requestUrl);
  String result="";
  try {
   URL url=new URL(requestUrl);
   HttpURLConnection connection=(HttpURLConnection)url.openConnection();
   connection.setDoOutput(true);
   connection.setDoInput(true);
   connection.setRequestMethod("GET");
   connection.setUseCaches(false);
   // URLConnection.setInstanceFollowRedirects是成员函数,仅作用于当前函数
   connection.setInstanceFollowRedirects(false);
   connection.setRequestProperty("Content-Type",
                "application/x-www-form-urlencoded");
   connection.connect();
   //发送执行请求
   
   //接收返回请求
   BufferedReader reader=new BufferedReader(new InputStreamReader(connection.getInputStream(),"GBK"));
   String line="";
   StringBuffer buffer=new StringBuffer();
   while((line=reader.readLine())!=null){
    buffer.append(line);
   }
   result=buffer.toString();
   System.out.println("result="+result);
   connection.disconnect();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

}

posted on 2013-01-06 21:36 abin 阅读(2649) 评论(1)  编辑  收藏 所属分类: HttpUrlConnection

Feedback

# re: HttpUrlConnection GET 2016-08-03 16:03 杀毒
是  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: