As we all know, the html5 interface of the project will be developed for a relatively long time (why is this not explained), and some problems that cannot be detected on the web end will occur in the browser, I have the idea of simulating a browser. After google, I found that there is a way to disguise the browser, that is, using the browser's user Agent (Each browser has its own different user Agent, in addition, you can use the user Agent to determine the token, UsedWhen a user initiates a request to the server through a browser, the request header (header) will contain ). After the installation is successful, you can see the Default User Agent option in the tool options. For example, after the test by the author,Is a specific Identifier of the browser, so the if statement in can determine whether the request is initiated by the browser. Note the following:In this paper, the author needs to use his own GT-I9300 to obtain the agent is: Open the Add new User Agent under the Default user agent to switch the user agent to the just built GT-9300 for testing: compare yourself to www.baidu.com the original look, it is added successfully.
String url = "http://www.where is your need.com" String userAgent = "Mozilla/5.0 (Linux; U; Android 4.1.2; zh-cn; GT-I9300 Build/JZO54K) "+" AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 MicroMessenger/5.2.380 "String html = getHttpClientHtml (url, "UTF-8" String html = HttpClient httpClient = DefaultHttpClient (); HttpGet httpget = HttpGet (url); httpget. setHeader ("User-Agent" HttpResponse responce = returnCode = (returnCode = HttpEntity entity = (entity! = Html = String (EntityUtils. toString (entity);} System. out. println ("exception occurred "}}