如题 代码如下public static String requestPost(String linkAddress, int timeout) {
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;
}
服务器端返回的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;
}
服务器端返回的state是200 也就是访问是成功的 但是为什么服务器端的流得不到呢? 流确实存在 我用手机就可以正常运行 ,而用模拟器就不行 ,求解? 其中setProxy()是设置代理 通过代理的方式访问的
解决方案 »
- 怎样基于BaseAdapter实现灵活的图片加载
- Android SDK 4.0.3环境下EditText组建的显示问题
- 从一个Activity中打开另一个Activity时出错。
- import com.android.common.Search出错
- 刚开始着手Android 麻烦大侠解决
- 播放HTTP大文件的问题
- 短信广播接收者,监听短信
- 怎么直接调用系统设置好的闹钟(自己解决了,来几个收分的)
- 为改变这个世界尽一份力量,请加入我们一起用移动互联网改变世界!
- android listview中checkbox控制点击数目。
- 安卓系统开发 点击图标调用浏览器打开特定的网址
- 关于setShortcut
state=200
能告诉我下是什么原因吗