Movatterモバイル変換


[0]ホーム

URL:


everything curl

    HTTP basics

    HTTP is a protocol that is easy to learn the basics of. A client connects to aserver—and it is always the client that takes the initiative—sends arequest and receives a response. Both the request and the response consist ofheaders and a body. There can be little or a lot of information going in bothdirections.

    An HTTP request sent by a client starts with a request line, followed byheaders and then optionally a body. The most common HTTP request is probablythe GET request which asks the server to return a specific resource, and thisrequest does not contain a body.

    When a client connects to 'example.com' and asks for the '/' resource, itsends a GET without a request body:

    GET / HTTP/1.1User-agent: curl/2000Host: example.com

    …the server could respond with something like below, with response headersand a response body ('hello'). The first line in the response also containsthe response code and the specific version the server supports:

    HTTP/1.1 200 OKServer: example-server/1.1Content-Length: 5Content-Type: plain/texthello

    If the client would instead send a request with a small request body('hello'), it could look like this:

    POST / HTTP/1.1Host: example.comUser-agent: curl/2000Content-Length: 5hello

    A server always responds to an HTTP request unless something is wrong.

    The URL converted to a request

    When an HTTP client is given a URL to operate on, that URL is then used,picked apart and those parts are used in various places in the outgoingrequest to the server. Let's take an example URL:

    https://www.example.com/path/to/file
    • https means that curl uses TLS to the remote port 443 (which is thedefault port number when no specified is used in the URL).

    • www.example.com is the hostname that curl resolves to one or more IPaddresses to connect to. This hostname is also used in the HTTP request intheHost: header.

    • /path/to/file is used in the HTTP request to tell the server which exactdocument/resources curl wants to fetch


    [8]ページ先頭

    ©2009-2025 Movatter.jp