package com.ygsoft.community.regulation.util; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.apache.http.NameValuePair; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; 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.HttpClientBuilder; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; public class HttpUtil { public static void main(String args[]) throws Exception { Map<String, String> map = new HashMap<String, String>(); map.put("flag", "0"); map.put("TypeID", "root_gr_ztfl_hj"); map.put("pageNo", "1"); map.put("pageSize", "100"); new HttpUtil().post(map, "http://wsbs.jinwan.gov.cn/wsbs/f/matterList"); } private String proxyHost; private int proxyPort; public HttpUtil() { this.proxyHost = "10.1.5.78"; this.proxyPort = 3128; } public HttpUtil(String proxyHost, Integer proxyPort) { this.proxyHost = proxyHost; this.proxyPort = proxyPort; } @SuppressWarnings("rawtypes") public String post(Map buzReqParams, String reqUrl) throws Exception { String result = null; // 创建HttpClientBuilder HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); // HttpClient CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); // 依次是目标请求地址,端口号,协议类型 HttpHost target = new HttpHost(reqUrl, 80, "http"); // 依次是代理地址,代理端口号,协议类型 HttpHost proxy = new HttpHost(this.proxyHost, this.proxyPort, "http"); RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); // 请求地址 HttpPost httpPost = new HttpPost(reqUrl); httpPost.setConfig(config); // 创建参数队列 List<NameValuePair> formparams = new ArrayList<NameValuePair>(); Set set = buzReqParams.keySet(); Iterator it = set.iterator(); while (it.hasNext()) { String key = (String) it.next(); formparams.add(new BasicNameValuePair(key, (String) buzReqParams .get(key))); } UrlEncodedFormEntity entity; try { entity = new UrlEncodedFormEntity(formparams, "UTF-8"); httpPost.setEntity(entity); CloseableHttpResponse response = closeableHttpClient.execute( target, httpPost); HttpEntity httpEntity = response.getEntity(); if (httpEntity != null) { result = EntityUtils.toString(httpEntity, "UTF-8"); // 打印响应内容 System.out.println("response:" + result); } // 释放资源 closeableHttpClient.close(); } catch (Exception e) { e.printStackTrace(); } return result; } }
相关推荐
在"icedemo"项目中,我们首先要创建Request和Response类。这些类可以是普通的Java类,通过序列化和反序列化机制与ICE通信。例如: ```java public class Request { private String methodName; private Object[] ...
cas 配置client 1.0 &2.0 及proxy DEMO 说明 1 cas server 搭建 1.1 资源准备 cas server 下载 http://www.ja-sig.org/downloads/cas/cas-server-3.3.1-release.zip 1.2 解压后打开cas-server-3.3.1-release\cas-...
MyResponse response = proxy.call(request); System.out.println(response.getResponse()); RPC.stopProxy(proxy); } } ``` 5. **运行和测试**:编译并运行服务器端和客户端程序,你应该能看到客户端从...
proxy_pass_request_headers on; proxy_set_header Cookie $http_cookie; proxy_set_header Set-Cookie $http_set_cookie; proxy_pass http://redis-server:6379; } } ``` 在这个配置中,`ip_hash`指令保证了...
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = ...
ip = request.getHeader("Proxy-Client-IP"); System.out.println("Proxy-Client-IP ip: " + ip); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-...
redirect就是服务端根据逻辑,发送一个状态码,告诉浏览器重新去请求那个地址,一般来说浏览器会用刚才请求的所有参数重新请求,所以session,request参数都可以获取。 23、EJB与JAVA BEAN的区别? Java Bean 是可...
NGINX auth_request指令确保使用OpenID Connect对所有对Opencast的请求进行身份验证。 由keycloak发出的ID令牌的处理在security-jwt模块中实现。 建筑 使用附加的security-jwt模块下载并构建Opencast: make build...
ProxyFactory.proxy 方法,生成接口的代理对象,直接调用方法客户端和服务器端的接口和实体类要一致,实体类必须是可以序列化的比如:定义Bean: public class DemoBean implements java.io.Serializable{ ...
<listener-class>org.springframework.web.context.request.RequestContextListener ``` ##### 2. 配置Spring applicationContext.xml 接下来,在`applicationContext.xml`文件中进行具体的Spring Bean配置: - ...
// 原始请求路径:http://localhost:10000/demo/list/data // 修改为:/api/prefix/list/data String modifiedRequestPath = "/api/prefix" + originalRequestPath; context.put(FilterConstants.REQUEST_URI_...
- **californium-proxy**: 实现CoAP到CoAP、CoAP到HTTP以及HTTP到CoAP的代理功能。 - **demo-xxx**: 示例程序,帮助用户理解和使用Californium。 3. **分层设计** - **网络层**:处理端口监听和网络数据的发送与...
3.4. HTTP 认证适配器 3.4.1. 简介 3.4.2. 设计回顾 3.4.3. 配置选项 3.4.4. Resolvers 3.4.4.1. 文件 Resolver 3.4.5. 基本用法 4. Zend_Cache 4.1. 简介 4.2. 缓存原理 4.2.1. Zend_Cache 工厂方法 ...
urllib.request urllib.robotparser venv warnings winreg winsound xmlrpc.client zipfile zlib Optimizations Build and C API Changes Other Improvements Deprecated New Keywords Deprecated ...