获取桌面网站的页面来源而不是移动网站

时间:2017-06-06 14:04:00

标签: java android android-studio

是否可以获取网站的桌面stie页面源而不是移动网站? 我的代码:

 public void test() {
    ;
 // Instantiate the RequestQueue.
    RequestQueue queue = Volley.newRequestQueue(this);
    String url = "google.com";

  // Request a string response from the provided URL.
    button = (TextView) findViewById(R.id.buttoneins);

    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) { 
               button.setText("Response is: " + response.substring(0,5532));
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            button.setText("That didn't work!");
        }
    });
    // Add the request to the RequestQueue.
    queue.add(stringRequest);
  }

1 个答案:

答案 0 :(得分:1)

尝试覆盖public Map<String, String> getHeaders()

 StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) { 
           button.setText("Response is: " + response.substring(0,5532));
            }
        }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        button.setText("That didn't work!");
    },
    @Override
    public Map<String, String> getHeaders() throws AuthFailureError { 
            Map<String, String>  params = new HashMap<String, String>();  
            params.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");  


            return params;  
    }

});