htmlunit 发http请求
生活随笔
收集整理的這篇文章主要介紹了
htmlunit 发http请求
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
htmlunit 發(fā)http請(qǐng)求 博客分類(lèi): java public static WebClient createWebClient(String ip, String port) {WebClient client = null;try {if (StringUtils.isBlank(ip) || StringUtils.isBlank(port)) {client = new WebClient(BrowserVersion.FIREFOX_24);} else {client = new WebClient(BrowserVersion.FIREFOX_24, ip,Integer.valueOf(port));}client.getOptions().setUseInsecureSSL(true);client.getOptions().setCssEnabled(false);client.getOptions().setJavaScriptEnabled(false);} catch (Exception e) {log.error(e);}return client;}public static String htmlUnitUrl(String url, WebClient webClient) {try {WebRequest request = new WebRequest(new URL(url), HttpMethod.GET);Map<String, String> additionalHeaders = new HashMap<String, String>();additionalHeaders.put("User-Agent","Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36");additionalHeaders.put("Accept-Language", "zh-CN,zh;q=0.8");additionalHeaders.put("Accept", "*/*");request.setAdditionalHeaders(additionalHeaders);// 獲取某網(wǎng)站頁(yè)面Page page = webClient.getPage(request);// System.out.println(Page.getWebResponse().getContentAsString());return page.getWebResponse().getContentAsString();} catch (Exception e) {log.error(e);}return null;}?
轉(zhuǎn)載于:https://my.oschina.net/xiaominmin/blog/1597899
總結(jié)
以上是生活随笔為你收集整理的htmlunit 发http请求的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: maven 生命周期
- 下一篇: CSS+DIV固定底部的漂浮导航条(多浏