httpclient 基础教程
- httpclient依懒包官网下载及httpclient maven依懒包获取
- httpClient快速入门
- httpclient get请求
- httpclient 带参数 get 请求
- httpclient post 请求
- httpclient 模拟浏览器请求
- httpclient post 表单参数请求
- HttpClient PUT请求示例
- HttpClient DELETE请求示例
httpclient 进阶教程
知识点
相关文章
更多最近更新
更多httpclient 模拟浏览器请求
2019-03-16 23:22|来源: 网路
httpclient伪装浏览器请求的核心思想是设置http请求头信息,如果User-Agent:
httpPost.setHeader("User-Agent","Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36");
示例:
package com._656463.httpclient; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; public class DoPOST { public static void main(String[] args) throws Exception { // 创建Httpclient对象 CloseableHttpClient httpclient = HttpClients.createDefault(); // 创建http POST请求 HttpPost httpPost = new HttpPost("http://www.oschina.net/"); httpPost.setHeader( "User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36"); CloseableHttpResponse response = null; try { // 执行请求 response = httpclient.execute(httpPost); // 判断返回状态是否为200 if (response.getStatusLine().getStatusCode() == 200) { String content = EntityUtils.toString(response.getEntity(), "UTF-8"); System.out.println(content); } } finally { if (response != null) { response.close(); } httpclient.close(); } } }
本文参考网络
相关问答
更多-
java 模拟登录问题,使用httpclient[2023-04-25]
需要先判断一下是否登陆成功,只要登陆成功client对象就应该得到cookie了,你就可以用这个client对象直接请求你需要的页面。如果不用状态码判断登陆成功,状态码可能就没什么用了。 -
httpclient + javascript(httpclient + javascript)[2023-05-17]
结帐http://htmlunit.sourceforge.net/ Checkout http://htmlunit.sourceforge.net/ -
HttpClient失败(HttpClient failing)[2022-07-12]
您的程序集绑定重定向是错误的。 您的iOS项目应该有一个包含以下内容的app.config文件:根据MSDN ,因为.NET 4.5以下实例方法是线程安全的 (感谢@ischell): CancelPendingRequests DeleteAsync GetAsync GetByteArrayAsync GetStreamAsync GetStringAsync PostAsync PutAsync SendAsync According to MSDN, since .NET 4.5 The following instance methods are thread safe (thanks @ ...您可以使用此代码前进,它适用于我.. URL url = new URL("Your URL"); HttpURLConnection httpsURLConnection = (HttpURLConnection)url.openConnection(); httpsURLConnection.setReadTimeout(15000); httpsURLConnection.setConnectTimeout(20000); httpsURLConnec ...处理注入的HttpClient(Dispose of Injected HttpClient)[2023-11-29]
处置HttpClient清除任何活动的取消令牌和任何部分完成的请求/响应。 在大多数正常情况下,处置它并不重要,尽管按惯例你应该。 请注意,处置HttpClient会强制关闭TCP连接。 如果您的MVC应用程序正在对同一台服务器进行大量调用,则可能需要跨越请求保留HttpClient实例并重新使用它。 这样可以避免每次都需要重新设置默认的请求标头,并且允许重新使用TCP连接。 Disposing HttpClient cleans up any active Cancellation tokens and ...HttpClient重定向(HttpClient redirecting)[2022-11-20]
这意味着给定的站点处于DDOS保护模式(也许你试图经常打开它?)解决方法你需要停止那么多(例如在尝试之间等待一段时间)。 或者,如果你坚持使用一些javascript执行库(Rhino?),它将执行cloudflare正在使用的javascript。 It means that given site is under DDOS protection mode (maybe you try to open it too often?) to workaround you would need to stop ...这只是一个不同的API。 Observable有更好的方法来分离“如何流动”(所有操作符:map,merge,concat等)与执行(.subscribe),这往往有助于获得更好的图片。 Plus提供有用的方法来取消或重试请求,如果失败。 如果你需要Promise API,你可以随时使用Observable.toPromise() (使用async / await,这也很有用) 所以对我来说,这只是表示同一事物的两种方式,每种方式都有其优势,但由于Observable更通用,他们使用了这种方法 - 可以将O ...本网站使用Incapsula的一些专用技术来防止自动访问网站。 在第一次请求时,该站点返回带有嵌入式iframe的Web文档。 只有在加载iframe源时,才会设置cookie并重定向到页面。 然后所有进一步的请求将立即成功,因为浏览器发送cookie信息。 为了规避机制,您必须在第一次请求后加载iframe,记住cookie然后发送cookie以获取所有进一步的请求。 第一个答案中还涉及很多JavaScript代码,可能必须执行Incapsula检查才能成功。 但是,当网站专门使用这种技术来防止自动访问其 ...