博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
httpclient post
阅读量:5102 次
发布时间:2019-06-13

本文共 4188 字,大约阅读时间需要 13 分钟。

package com.dianping.cscCaseSevice;import net.sf.json.JSONObject;import org.apache.commons.httpclient.HttpClient;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;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.entity.StringEntity;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClients;import org.apache.http.message.BasicNameValuePair;import org.apache.http.util.EntityUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;import org.testng.annotations.Test;import org.apache.http.NameValuePair;import com.dianping.csc.platform.csccase.api.dto.CscCaseDto;import com.dianping.csc.platform.csccase.api.enums.CscCaseStatusEnum;import com.dianping.csc.platform.csccase.api.enums.CustomerType;import com.dianping.csc.platform.csccase.api.enums.PriorityType;import com.dianping.csc.platform.csccase.api.dto.CscCaseTakeOutDto;import com.dianping.csc.platform.csccase.api.enums.CompensateModeEnum;import com.dianping.csc.platform.csccase.api.enums.EvidenceSendWayEnum;import java.io.IOException;import java.math.BigDecimal;import java.util.ArrayList;import java.util.Arrays;import java.util.Date;import java.util.List;/** * Created by zjj on 16/5/24. */public class testCreateCaseForMovie {    @Test    public void test(){           // 创建默认的httpClient实例.            CloseableHttpClient httpclient = HttpClients.createDefault();           // 创建httppost            HttpPost method = new HttpPost("http://10.66.56.86:8080/api/case/createCaseForMovie");           // 创建参数队            List
nvps = new ArrayList
(); Date d = new Date(); nvps.add(new BasicNameValuePair("sfCaseId", "1"));// 红谷滩新闻资讯,channelId 77 nvps.add(new BasicNameValuePair("customerName", "meme"));// 标题 nvps.add(new BasicNameValuePair("bindNumber", "123"));// 资讯内容 nvps.add(new BasicNameValuePair("callerNumber", "1234"));// 资讯源地址 nvps.add(new BasicNameValuePair("dealGroupId", "123456"));// 来源网站名称 nvps.add(new BasicNameValuePair("dealGroupName", "keyide"));// 采用 url,url,url 的格式进行图片的返回 nvps.add(new BasicNameValuePair("orderType", "2")); nvps.add(new BasicNameValuePair("comments", "可以吧")); nvps.add(new BasicNameValuePair("caseContent", "又有")); nvps.add(new BasicNameValuePair("acceptId", "123")); nvps.add(new BasicNameValuePair("acceptGroupId", "234")); nvps.add(new BasicNameValuePair("customerRequire","2345")); nvps.add(new BasicNameValuePair("orderNumber","234567")); nvps.add(new BasicNameValuePair("dealPeriod", "20")); try { HttpEntity entity = new UrlEncodedFormEntity(nvps,"utf-8"); method.setEntity(entity); try { CloseableHttpResponse result = httpclient.execute(method); if (result != null) { String resData = EntityUtils.toString(result.getEntity()); System.out.println("--------------------------------------"); System.out.println("Response content: " + resData); System.out.println("--------------------------------------"); method.abort(); } } catch (Exception e){} finally { // 关闭连接,释放资源 try { httpclient.close(); } catch (IOException e) { e.printStackTrace(); } } } catch (Exception E){} }}

 

转载于:https://www.cnblogs.com/dudu234/p/5523828.html

你可能感兴趣的文章
Hadoop简单介绍
查看>>
面向对象程序设计的思想的长处
查看>>
通过路径传值id进行页面判断
查看>>
获取文本的值
查看>>
spring security 参考 和 例子
查看>>
W3C-Web Service
查看>>
添加field部署
查看>>
CF-补题1
查看>>
SQL SERVER 读取 XML 数据
查看>>
URLClassLoader
查看>>
shell入门之流程控制语句 分类: 学习笔记 li...
查看>>
UML学习-时序图
查看>>
接口测试工具-Jmeter使用笔记(五:正则表达式提取器)
查看>>
Java线程之生命周期
查看>>
WPF与输入法冲突研究之三:韩文输入法在不同平台,WinForm/WPF下的区别
查看>>
js中的数据转换、整数、小数保存、四舍五入
查看>>
安装redis
查看>>
office如何去除多页签
查看>>
Vue.js刷新当前页面
查看>>
php 反射
查看>>