x-www-form-urlencoded请求封装
2024-10-21 16:04:33
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
public static String postJsonMethodParamsEncode(String postURL,Map<String,String> destMap){
log.info("postJsonMethodParamsEncode request postURL:{}",postURL);
try {
PostMethod postMethod = null;
postMethod = new PostMethod(postURL) ;
postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") ;
NameValuePair[] data = new NameValuePair[destMap.size()];
int i = 0;
for (String key : destMap.keySet()){
data[i] = new NameValuePair(key,destMap.get(key));
i++;
} postMethod.setRequestBody(data);
HttpClient httpClient = new HttpClient();
int response = httpClient.executeMethod(postMethod);
return postMethod.getResponseBodyAsString() ;
} catch (Exception e) {
log.error("请求异常:",e);
throw new RuntimeException(e.getMessage());
}
}
最新文章
- JQuery------分页插件下载地址
- 关于C语言的问卷调查
- WCF 服务的ABC之绑定(六)
- 使用spm build 批量打包压缩seajs 代码
- 重拾C++ 基础知识总结(一)
- linkin大话数据结构--Collection和Iterator
- 【C语言】多项式加法(mooc第七周测试题)
- python中os模块操作目录与文件名小结
- OpenCV 学习笔记 06 图像检索以及基于图像描述符的搜索
- 2-sat相关复习
- ubuntu vi配置
- nginx的启动和关闭
- 安装配置SVN
- IP地址分配机构
- zTree第二章,各种常见setting设置和方法
- 【转载】MDX Step by Step 读书笔记(四) - Working with Sets (使用集合)
- Linux下的高级拾色器—Pick
- STL源码剖析(deque)
- Alpha matting算法发展
- [ZOJ3316]Game