Skip to content
CheckcraftDownload
Practical workflow

HTTP requests from 1C: GET, POST, headers, auth and timeouts with examples

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →

In 1C:Enterprise 8.3 an HTTP request is built from two objects: HTTPConnection knows the server, port, secure connection and timeout, and HTTPRequest holds the path, headers and body. Below are working GET and POST samples, auth, parameters and response checks.

Checkcraft ·

Get help with your first test →

What an HTTP request in 1C consists of

HTTPConnection is created for a server, not a full URL: the first parameter is just the host name without https:// or a path. The path with parameters goes into HTTPRequest. HTTPS needs an OpenSSLSecureConnection object, otherwise the request goes over plain HTTP or fails.

Which method to call

GET is sent with Get, POST with Post, PUT with Put, DELETE with Delete. For PATCH and any other method use CallHTTPMethod with the method name as the first parameter. All of them return an HTTPResponse with the status code, headers and body.

API call diagram: method and URL, headers, body, status and response body, logs and database

How to check the response

First the status code, then the content type, and only then the body. A 200 with an HTML login page or a 500 with an error text must not reach JSON parsing. Read the body with GetBodyAsString and an explicit UTF-8 encoding.

How to repeat the request without 1C

If it is unclear whether 1C or the service is at fault, repeat the same request with curl or an API client using the same address, headers and body. Same result means the service. A different result means 1C sends something else: an extra BOM, another Content-Type, a path with a double slash.

Layers of an API call check: status, headers, body, calculations, logs, database

GET with HTTPS, headers and a token

Соединение = Новый HTTPСоединение("api.example.com", 443, , , , 30,
    Новый ЗащищенноеСоединениеOpenSSL(, Новый СертификатыУдостоверяющихЦентровОС));

Запрос = Новый HTTPЗапрос("/api/orders?status=NEW&limit=50");
Запрос.Заголовки.Вставить("Accept", "application/json");
Запрос.Заголовки.Вставить("Authorization", "Bearer " + Токен);

Ответ = Соединение.Получить(Запрос);
Сообщить(Ответ.КодСостояния);
Тело = Ответ.ПолучитьТелоКакСтроку("UTF-8");

Query parameters go straight into the HTTPRequest path. Encode values with spaces and Cyrillic with EncodeString and URL encoding, or the server gets something else.

POST, PUT, DELETE and PATCH

Запрос = Новый HTTPЗапрос("/api/orders");
Запрос.Заголовки.Вставить("Content-Type", "application/json; charset=utf-8");
Запрос.УстановитьТелоИзСтроки(СтрокаJSON, "UTF-8", ИспользованиеByteOrderMark.НеИспользовать);

Ответ = Соединение.ОтправитьДляОбработки(Запрос);   // POST
// Соединение.Записать(Запрос)                       // PUT
// Соединение.Удалить(Запрос)                        // DELETE
// Соединение.ВызватьHTTPМетод("PATCH", Запрос)      // любой другой метод

Basic and Bearer auth

// Basic: логин и пароль в параметрах соединения
Соединение = Новый HTTPСоединение("erp.example.local", 80, "Обмен", Пароль, , 30);

// или заголовком, если сервис ждёт именно его
Данные = ПолучитьДвоичныеДанныеИзСтроки("Обмен:" + Пароль, КодировкаТекста.UTF8, Ложь);
Запрос.Заголовки.Вставить("Authorization", "Basic " + Base64Строка(Данные));

A Bearer token goes in the Authorization header as in the GET example. Keep tokens and passwords in secure storage, not in module code.

HTTPConnection methods

HTTP method1C methodWhen
GETПолучить (Get)Read data
POSTОтправитьДляОбработки (Post)Create an object, send data
PUTЗаписать (Put)Replace an object
DELETEУдалить (Delete)Delete an object
PATCH and othersВызватьHTTPМетод (CallHTTPMethod)Partial updates and custom methods

Common mistakes in request code

  • A full https:// URL passed to HTTPConnection instead of the host.
  • No OpenSSLSecureConnection for HTTPS.
  • A UTF-8 body with a BOM, and the partner service answers 400.
  • No timeout or one too short for a long operation.
  • The response is parsed as JSON without checking the status code.

If the request throws an exception, see HTTP request error in 1C.

More on 1C

Section overview and all guides: 1C integration via API: options, architecture and examples.

Frequently asked questions

How do I send a POST from 1C?

Create an HTTPConnection to the host, an HTTPRequest with the path, set Content-Type and the body with SetBodyFromString, then call Post.

How do I set a timeout?

The sixth parameter of the HTTPConnection constructor, in seconds. Zero or empty means no limit.

Why can’t I pass a full URL to HTTPConnection?

The first parameter is only the server name. https is set with an OpenSSLSecureConnection object and the path goes into HTTPRequest.

Next step

Repeat this on your own API

Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.

Download FreeDownload and first run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

References

RFC 9110: HTTP semantics

Start with the linked example and compare its result with your own test requirement.

Ask a person

Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

No account required. We will reply by email. This is a support request, not a newsletter subscription.