zoukankan      html  css  js  c++  java
  • 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://**********/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异常,是依赖的包没有导完整

  • 相关阅读:
    截取url中最后斜杆的文件名
    html span从上往下,从左往右排序
    浪漫源码记录
    微信小程序TypeError: Cannot read property 'elem' of undefined
    tomcat8 性能优化
    Bandicam神奇使用法
    DataStage 七、在DS中使用配置文件分配资源
    DataStage 六、安装和部署集群环境
    DataStage 错误集(持续更新)
    DataStage 三、配置ODBC
  • 原文地址:https://www.cnblogs.com/duanxianyouyang/p/9908569.html
Copyright © 2011-2022 走看看