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();
}
}
}