qq_29208361 2015-08-12 10:49 采纳率: 0%
浏览 1633

android真机调试,获取网页源代码,返回302.请大神指点迷津,万分感谢!

获取网页源代码,返回code是302 用真机调试 ,请大神指点迷津,万分感谢!
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)");
int code = conn.getResponseCode();
if(code==200){
InputStream is = conn.getInputStream();
String result = StreamTools.readInputStream(is);

                        Message msg = new Message();
                        msg.what = SHOW_TEXT;
                        msg.obj = result;
                        handler.sendMessage(msg);
                        //tv_content.setText(result);
                    }else {
                        Log.i(LAG,code+"");
                        Message msg = new Message();
                        msg.what = ERROR;
                        handler.sendMessage(msg);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    Message msg = new Message();
                    msg.what = ERROR;
                    handler.sendMessage(msg);
  • 写回答

3条回答 默认 最新

  • tommy19811027 2015-08-12 10:55
    关注

    类似问题,等待答案学习!

    评论

报告相同问题?

悬赏问题

  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题