How to add,set and get Header in request of HttpClient?

后端 未结 3 1256
别跟我提以往
别跟我提以往 2020-12-14 01:48

In my application I need to set the header in the request and I need to print the header value in the console... So please give an example to do this the HttpClient or edit

3条回答
  •  孤城傲影
    2020-12-14 02:16

    You can use HttpPost, there are methods to add Header to the Request.

    DefaultHttpClient httpclient = new DefaultHttpClient();
    String url = "http://localhost";
    HttpPost httpPost = new HttpPost(url);
    
    httpPost.addHeader("header-name" , "header-value");
    
    HttpResponse response = httpclient.execute(httpPost);
    

提交回复
热议问题