是否可以获取网站的桌面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);
}
答案 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;
}
});