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

后端 未结 3 1248
别跟我提以往
别跟我提以往 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:25

    On apache page: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html

    You have something like this:

    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost("www.google.com").setPath("/search")
        .setParameter("q", "httpclient")
        .setParameter("btnG", "Google Search")
        .setParameter("aq", "f")
        .setParameter("oq", "");
    URI uri = builder.build();
    HttpGet httpget = new HttpGet(uri);
    System.out.println(httpget.getURI());
    

提交回复
热议问题