2014-11-25 40 views

回答

1

您應該爲您的請求設置標題。我想,你應該設置User-Agent頭來獲得完整版本。

例如,如果使用HTTPGET比:

DefaultHttpClient httpClient = new DefaultHttpClient(); 
final HttpParams httpParameters = httpClient.getParams(); 

HttpConnectionParams.setConnectionTimeout(httpParameters, 8 * 1000); 
HttpConnectionParams.setSoTimeout(httpParameters, 8 * 1000); 

HttpGet httpGet = new HttpGet(url); 
httpGet.addHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0");  
+0

添加一段代碼:) – 2014-11-25 11:48:12

+0

@LittleChild完成) – Suvitruf 2014-11-25 11:54:16

+0

非常感謝!它幫助! – 2014-11-25 15:19:25

2

你是如何試圖下載的html頁面?我正在用某種webview進行猜測。

,如果你下載這個樣子,它應該有桌面版的全部內容:

URL url = new URL("https://stackoverflow.com/questions/1381617"); 
URLConnection con = url.openConnection(); 
Reader r = new InputStreamReader(con.getInputStream(), Charset.forName("UTF-8")); 
StringBuilder b = new StringBuilder(); 
while (true) { 
    int ch = r.read(); 
    if (ch < 0) 
    break; 
    b.append((char) ch); 
} 
String s = b.toString(); 

Simplest way to correctly load html from web page into a string in Java

+0

謝謝,但我想獲得桌面版本的頁面,並需要模仿桌面設備。 – 2014-11-25 15:20:44