如题 代码如下
public static String requestPost(String linkAddress, int timeout) {服务器端返回的state是200 也就是访问是成功的 但是为什么服务器端的流得不到呢? 流确实存在 我用手机就可以正常运行 ,而用模拟器就不行 ,求解? 其中setProxy()是设置代理 通过代理的方式访问的
String result = null;
try {
URL url = new URL(linkAddress);
setProxy();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(timeout * 1000);
conn.connect();
int state = conn.getResponseCode();
System.out.println(state);
System.out.println(linkAddress);
if (state == HttpURLConnection.HTTP_OK) {
InputStream in = conn.getInputStream();
System.out.println("$$$$$$"+in.available());
BufferedReader reader = new BufferedReader(new InputStreamReader(in, HTTP.UTF_8));
String line = null;
while ((line = reader.readLine()) != null) {
if(result==null){
result=line;
}else{
result += line;
}
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
------解决方案--------------------
用设备测试吧,