User agent: user agent. It is a kind of identification that provides information such as browser type, operating system and version, CPU type, browser rendering engine, browser language, browser plug-in, etc. The UA string is sent to the server every time the browser makes an HTTP request
Referer: http referer is a part of the header. When a browser sends a request to a web server, it usually brings a referer to tell the server which page I’m linking from, so that the server can get some information for processing
public static String getHtmls(String url) throws IOException {
RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
String html = "";
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(globalConfig).build();
HttpGet httpget = new HttpGet(url);
//Browser identifier (OS identifier; encryption level identifier; browser language) Rendering engine identifier Version information
httpget.setHeader("User-Agent","Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255");
// Camouflage head
httpget.setHeader("Referer", "https://mp.weixin.qq.com");
try {
HttpResponse responce = httpClient.execute(httpget);//
int resStatu = responce.getStatusLine().getStatusCode();
if (resStatu == HttpStatus.SC_OK) {
HttpEntity entity = responce.getEntity();
if (entity != null) {
html = EntityUtils.toString(entity);// Get html source code
}
}
} catch (Exception e) {
System.out.println("request " + url + " error!");
e.printStackTrace();
} finally {
// close
httpClient.close();
}
return html;
}
Read More:
- IOS WebView failed to load the web page. Error domain = kcferrodomaincfnetwork code = 310 “there was a problem communicating with the secure web proxy server (HTTPS). “
- QQ browser open automatically appear two web page solution
- The local web page in WebView failed to load with XMLHttpRequest
- Coursera Using python to access Web data quiz 4
- The web project removal server reports an error, and the web project in eclipse cannot be automatically deployed to Tomcat
- Breaking the web page to prevent copying
- stay web.xml Configure error page in
- How to Fix IWAB0489E Error when deploying Web service to Axis runtime
- Error in Maven packaging web project: webxml attribute is required (or pre existing WEB-INF)/ web.xml if executing in update)
- web.xml Web app error in file
- There is more than one Web fragment with the same name: “spring_web”.
- WeChat official account web page authorized, redirect_ Uri parameter error, solution!
- How to solve the problem of “blocked loading mixed active content” in Firefox
- Three ways to get form data in struct2
- use cin.get () instead of system (“pause”) to avoid the flash of C + + programs
- About the steps to create Maven’s (WEB) dependency using in idea
- Chrome setting — Disable web security to solve cross domain problems
- How to avoid OrderSend Error 130 in MT4
- “503 Service Unavailable” error when connecting to vCenter Server using vSphere Web Client (2121043)
- Virtual host running ASP error resolution: HTTP/1.1 New Application Failed when allowSessionState is set to false in web.config