2017-06-06 97 views
0

是否有可能獲得網站的桌面站點頁面源代替移動網站? 我的代碼:獲取該頁面桌面站點的來源不是移動站點

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

回答

0

嘗試重寫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; 
    } 

}); 
+0

非常感謝,它工作:) – murph24