zoukankan      html  css  js  c++  java
  • HttpClient(4.3.5)

    HTTP Request

    All HTTP requests have a request line consisting a method name, a request URI and an HTTP protocol version.

    HttpClient supports out of the box all HTTP methods defined in the HTTP/1.1 specification: GETHEADPOSTPUTDELETETRACE and OPTIONS. There is a specific class for each method type.: HttpGetHttpHeadHttpPostHttpPutHttpDeleteHttpTrace, and HttpOptions.

    The Request-URI is a Uniform Resource Identifier that identifies the resource upon which to apply the request. HTTP request URIs consist of a protocol scheme, host name, optional port, resource path, optional query, and optional fragment.

    HttpGet httpget = new HttpGet(
         "http://www.google.com/search?hl=en&q=httpclient&btnG=Google+Search&aq=f&oq=");

    HttpClient provides URIBuilder utility class to simplify creation and modification of request URIs.

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

    stdout >

    http://www.google.com/search?q=httpclient&btnG=Google+Search&aq=f&oq=

    HTTP Response

    HTTP response is a message sent by the server back to the client after having received and interpreted a request message. The first line of that message consists of the protocol version followed by a numeric status code and its associated textual phrase.

    HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 
    HttpStatus.SC_OK, "OK");
    
    System.out.println(response.getProtocolVersion());
    System.out.println(response.getStatusLine().getStatusCode());
    System.out.println(response.getStatusLine().getReasonPhrase());
    System.out.println(response.getStatusLine().toString());

    stdout >

    HTTP/1.1
    200
    OK
    HTTP/1.1 200 OK
  • 相关阅读:
    关于CSS/Grid Layout实例的理解
    关于对CSS position的理解
    接上一条博客
    搬迁声明
    自动化测试流程
    浏览器测试app-H5页面使用appium实现自动化
    RSA加密算法坑:pyasn1-error-when-reading-a-pem-string
    parameter/argument, Attribute/Property区别
    本地mysql用Navicat链接报错 Authentication plugin 'caching_sha2_password' cannot be loaded
    mysql安装忘记root密码,初始化密码
  • 原文地址:https://www.cnblogs.com/huey/p/5720642.html
Copyright © 2011-2022 走看看