分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

HTTP发送RAW请求注意的问题

发布时间:2023-09-06 02:21责任编辑:胡小海关键词:暂无标签

1.使用jar

httpcomponents-client-4.5.6-bin.tar.gz

解压后倒入lib中的所有包

2.参考代码如下

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;


import org.apache.http.util.EntityUtils;


public class HttpClientTest {
public static void main (String args[]) throws ClientProtocolException, IOException {
??String url="http://10.1.14.47:7001/tppservice/es/zytWtService";
??String outputStr="{\"head\":{\"userId\":\"\",\"subsystem\":\"ZYT_APP\",\"subject\":\"ZYT_WT_001\",\"token\":\"TPP_ZYT\",\"sign\":\"d5682c3f2bede511d3f0b1fac3598454\",\"serialNo\":\"1412660\",\"transDate\":\"2018-11-02 16:09:20\"},\"busi\":{\"flag\":\"1\",\"pwd\":\"www123456\",\"userName\":\"18500000058\"}}";
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
StringEntity postingString = new StringEntity(outputStr);// json传递
post.setEntity(postingString);
post.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(post);
String content = EntityUtils.toString(response.getEntity());
System.out.println(content);
}
}

3.包导的不对会报NoClassDefFoundError: org.apache.commons.logging.LogFactory异常,是依赖的包没有导完整

HTTP发送RAW请求注意的问题

原文地址:https://www.cnblogs.com/duanxianyouyang/p/9908569.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved