HTTP发送RAW请求注意的问题

Posted duanxianyouyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTTP发送RAW请求注意的问题相关的知识,希望对你有一定的参考价值。

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请求注意的问题的主要内容,如果未能解决你的问题,请参考以下文章

NodeJS - TCP - 发送 HTTP 请求

socket转发http请求注意事项

php提前输出响应及注意问题

Http请求工具postman使用注意事项

防止使用 fetch 发送多个 http 请求

微信公众平台中开放的消息接口,详细怎么用?我的$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];为空?