java put方式

package com.test;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.impl.client.HttpClientBuilder;

import org.apache.http.*;


public class test
{
    public static void main(String[] args) throws Exception {
        testUpdate();
    }
    public static void testUpdate() throws Exception {
        String url = "";
        HttpClient client = HttpClientBuilder.create().build();
        HttpPut put = new HttpPut(url);
        put.setHeader("Content-type", "application/json");
//      StringEntity params =new StringEntity(jo.toString());
//      put.setEntity(params);
        HttpResponse response = client.execute(put);
           Header[] headers = response.getAllHeaders();
           for(int i=0;i<headers.length;i++) {
               System.out.println(headers[i].getName() +"=="+ headers[i].getValue());
              }
        System.out.println("Response Code:"+response.getStatusLine().getStatusCode());
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null) {
        result.append(line);
        }
        System.out.println("result:"+result);
    }
}

标签: none

添加新评论