Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Use HttpClient remote interface testing     - Qt shared memory interprocess communication (Programming)

- Zabbix monitoring different versions of RAID installation and monitoring and MySQL master-slave monitor (Server)

- Getting CentOS Learning Notes (Linux)

- Ubuntu users to install Gnome-Pie 0.6.5 (Linux)

- Android studio multi-channel ultra-compact version of the package (Programming)

- Oracle 11g + RAC + RHEL6.5 + udev + ASM + PSU installation summary (Database)

- BGP routers want to play it by CentOS (Linux)

- Hunk / Hadoop: Performance Best Practices (Server)

- Ubuntu comes with gedit editor to add Markdown preview widget (Linux)

- Install RAID 6 (Striping double distributed parity) (Linux)

- OpenSUSE / Linux network configuration (Linux)

- Use Ambari rapid deployment Hadoop big data environment (Server)

- The basic principles for the protection of a good linux server security (Linux)

- Offline (local) Yum source structures (Linux)

- Upgrading Oracle to (Database)

- How to modify the SQL Server auto-increment value and the corresponding solution (Database)

- Git Tutorial Comments (Linux)

- OpenWrt modify flash size (Linux)

- The method of Linux into the rescue mode (Linux)

- How to install Linux Go Language (Linux)

  Use HttpClient remote interface testing
  Add Date : 2018-11-21      
  Two days before the job, project leader gave me a remote interface to let me test it, because it is the http protocol, so I first thought of using httpClient tools to test, a search online, find a lot of sample code, casual copy a demo of a simple modification, the results of how tests are connection timeout, try a lot so that is not a demo, because we finally found a company to access the Internet through a proxy, so to perform this test you need to configure the agent .

The following is my test program

Use HttpClient remote interface testing

Jar kits:

package com.lym.test;

import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
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.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import com.google.gson.JsonObject;

public class HttpClientTest {
    public static void main (String args []) throws Exception {
        // Create HttpClientBuilder
        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create ();
        // HttpClient
        CloseableHttpClient closeableHttpClient = httpClientBuilder.build ();
        // Followed by requests for a destination address, port number, protocol type
        HttpHost target = new HttpHost ( "", 8888, "http");
        // Followed by the proxy address, proxy port number, protocol type
        HttpHost proxy = new HttpHost ( "proxy3.bj.petrochina", 8080, "http");
        . RequestConfig config = RequestConfig.custom () setProxy (proxy) .build ();

        // Address request
        HttpPost httpPost = new HttpPost ( "");
        // Set header
        httpPost.addHeader ( "Content-type", "application / json; charset = utf-8");
        httpPost.setHeader ( "Accept", "application / json");
        httpPost.setConfig (config);
        // Create a string parameter json
        JsonObject jsonObj = new JsonObject ();
        jsonObj.addProperty ( "merchantNo", "33300911238");
        jsonObj.addProperty ( "merchantName", "electricity supplier production test operations 1238");
        String jsonStr = jsonObj.toString ();
        System.out.println ( "parameters:" + jsonStr);
        StringEntity entity;
        try {
            entity = new StringEntity (jsonStr, "UTF-8");
            httpPost.setEntity (entity);
            CloseableHttpResponse response = closeableHttpClient.execute (target, httpPost);
            // GetEntity ()
            HttpEntity httpEntity = response.getEntity ();
            if (httpEntity! = null) {
                // Print the content of the response
                System.out.println ( "result:" + EntityUtils.toString (httpEntity, "UTF-8"));
            } Else {
                System.out.println ( "no response content");
            // Release resources
            if (closeableHttpClient! = null) {
                closeableHttpClient.close ();
        } Catch (Exception e) {
            e.printStackTrace ();
- A new method for Linux hidden files (Linux)
- Docker build private warehouse (Server)
- UUID in Java (Programming)
- How to install CentOS 7.x in OpenERP (Odoo) (Linux)
- A key installation Gitlab 7 on RHEL6.4 and Setup Mail TX (Linux)
- How to install with JSON support in Ubuntu 15.04 SQLite 3.9.1 (Database)
- Hadoop virtualization performance comparison and tuning experience (Server)
- Install the latest Pinta graphics editing software on Ubuntu 14.04 (Linux)
- The difference Docker save and export commands (Linux)
- Learning OpenCV: (VS2010-openCV2.4.3-win7 configuration instructions) (Linux)
- Ubuntu 15.10 install the latest Arduino IDE 1.6.7 (Linux)
- SSL VPN SSL VPN access to security websites patron (Linux)
- Oracle database, some basic grammatical structures (Database)
- Linux basis: a comprehensive study pwd command (Linux)
- Linux firewall security (Linux)
- Orionode source Linux Mint installation (Linux)
- Java Set and List in the relationship and difference (Programming)
- Using Java arrays implement sequential stack (Programming)
- Quickly build and install Linux KVM system (Linux)
- Proficient in C / C ++ can also find a very good job (Programming)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.