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.
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.

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.

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 method | 1C method | When |
|---|---|---|
| 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.
- HTTP request failed in 1C: causes and fixes
- OData in 1C: setup, queries and REST integration with examples
- 1C web services (SOAP): create, publish, WSDL and calls with examples
- Publishing 1C on IIS and Apache: step by step and common errors
- JSON in 1C:Enterprise: read, write, HTTP requests and common errors
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.
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 runNo sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.
References
Start with the linked example and compare its result with your own test requirement.