# Network

The functions for network/internet operations are described here.

* [Download( str url, str filename ) int](/stdlib/network.md#download-str-url-str-filename-int)
* [HeadInfo( str url ) hinfo](/stdlib/network.md#headinfo-str-url-hinfo)
* [HTTPGet( str url ) buf](/stdlib/network.md#httpget-str-url-buf)
* [HTTPPage( str url ) str](/stdlib/network.md#httppage-str-url-str)
* [HTTPRequest( str url, str method, map.str params, map.str headers ) str](/stdlib/network.md#httprequest-str-url-str-method-map-str-params-map-str-headers-str)

## Types

### hinfo

The *hinfo* type is used to get url address information and has the following fields:

* **int Status** - response status.
* **int Length** - content size. It may not be specified (equal to 0).
* **str Type** - content type. For example, *text/html; charset=UTF-8*.

## HTTP functions

### Download( str url, str filename ) int

The *Download* function downloads the file from the specified URL and saves it with the specified filename. The function returns the size of the downloaded file.

```go
    str ftemp = TempDir() + `/readme.html`
    int size = Download("https://github.com/gentee/gentee", ftemp)
```

### HeadInfo(str url) hinfo

The *HeadInfo* function sends a **HEAD** request to the specified *url* and returns the *hinfo* structure.

### HTTPGet( str url ) buf

The *HTTPGet* function sends a GET request to the specified URL and returns a response as a *buf* variable. The function can be used to download small files without saving them to disk.

### HTTPPage( str url ) str

The *HTTPPage* function sends a GET request to the specified URL and returns a string response.

### HTTPRequest( str url, str method, map.str params, map.str headers ) str

The *HTTPRequest* function sends an HTTP request to the specified URL and returns the response as a string. In the *method* parameter you need to specify the calling method - **GET, POST, UPDATE, PUT, DELETE**. The function also allows you to specify parameters and request headers. They are described as associative arrays where parameter name or header name is specified as a key. By default, the parameters are passed as form data when *POST* is called. If you want to send them in JSON format, then specify *"Content-Type": "application/json; charset=UTF-8"* in the *headers* parameter.

```go
    map empty
    Println(HTTPRequest(TESTURL, "GET", empty, empty))
    map params = { `name`: `Jong Doe`, `id`: `101` }
    Println(HTTPRequest(TESTURL, "GET", params, empty))
    Println(HTTPRequest(TESTURL, "POST", params, empty))
    map headjson = { `Content-Type`: `application/json; charset=UTF-8` }
    Println(HTTPRequest(TESTURL, "POST", params, headjson))
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gentee.org/stdlib/network.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
