B
B
Bartholomew Izoldin2016-12-02 14:11:40
JSON
Bartholomew Izoldin, 2016-12-02 14:11:40

How to make a POST request to a script on a site with JSON data transfer from 1C?

Good day to all. I can’t figure out how to send a POST request to a script on a data site in json format from 1C.
In php script just

var_dump($_POST);
var_dump($_GET);

In 1s
тЗаписьJSON = Новый ЗаписьJSON;
    тПараметрыJSON = Новый ПараметрыЗаписиJSON(ПереносСтрокJSON.Нет, " ", Истина);  
    тЗаписьJSON.УстановитьСтроку(тПараметрыJSON);   
    массивЧегото    = Новый Массив; 
    сЗаказы         = Новый Структура;  
    тДанные = Новый Структура;
    тДанные.Вставить("ЧислоJSON", 100);
    тДанные.Вставить("СтрокаJSON", "test");
    массивЧегото.Добавить(тДанные); 
    тДанные = Новый Структура;
    тДанные.Вставить("ЧислоJSON", 101);
    тДанные.Вставить("СтрокаJSON", "test1");
    массивЧегото.Добавить(тДанные); 
    сЗаказы.Вставить("xxx", массивЧегото);
    ЗаписатьJSON(тЗаписьJSON, сЗаказы);
    strJSON = тЗаписьJSON.Закрыть();

    Соединение = Новый HTTPСоединение(ИмяСайта);
    HTTPЗапрос = Новый HTTPЗапрос(ИмяСкрипта); 
    HTTPЗапрос.Заголовки.Вставить("Content-type", "application/json");
    HTTPЗапрос.УстановитьТелоИзСтроки(strJSON,КодировкаТекста.UTF8,ИспользованиеByteOrderMark.НеИспользовать);
    ИмяФайлаОтвета = ПолучитьИмяВременногоФайла("txt"); 
    Соединение.ОтправитьДляОбработки(HTTPЗапрос, ИмяФайлаОтвета);   
    ФайлОтвета = Новый Файл(ИмяФайлаОтвета);

At the output in the response file I have
array(0) {
}
array(0) {
}

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kinash, 2016-12-02
@izoldin

What did you expect to see? Everything is correct - according to the listing, you did not pass a single variable to your script either by the GET method or by the POST method.
Clue. Request body <> parameter passing by POST method. The parameter is at least the name, and you only have the content.
Either format the content correctly in the strJSON variable (if you're too lazy to read the RFC, then peep the correct structure with a sniffer), or take the complete request content ($HTTP_RAW_POST_DATA) in your PHP script - this will be your JSON.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question