Как составить POST запрос

maxim.gutareff

Пользователь
Регистрация
27.01.2018
Сообщения
240
Благодарностей
16
Баллы
18
Есть АПИ сервиса. Составил код на PHP на отправку сообщения в ватсап.

Указываю в кубике POST в URL адрес:

В поле "Данные" указываю код:
$token = 'PtuFw4ENgxUZXd3884c4d026a76ec951c0ea89dfbad52';

$array = array(
array(
'chatId' => '[email protected]', // Телефон получателя
'message' => 'Hello!', // Сообщение
)
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.api-messenger.com/sendmessage?token=' . $token);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json; charset=utf-8'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$result = curl_exec($ch); // Отправим запрос
curl_close($ch);
$data = json_decode($result, true); // Разберем полученный JSON в массив
echo $data['status'] . ': ' . $data['message'];


И ничего не отправляется. Как правильно нужно создавать кубик POST запроса? Первый раз с ними работаю.
Инструкция вот: https://api-messenger.com/ru/documentations/
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 765
Благодарностей
2 407
Баллы
113
Примерно так, если json должен быть такой:
JSON:
[[{"chatId":"[email protected]","message":"Hello!"}]]
C#:
string token = "PtuFw4ENgxUZXd3884c4d026a76ec951c0ea89dfbad52";
string url = string.Format("https://app.api-messenger.com/sendmessage?token={0}",token );
string proxy = "";
string UserAgent = project.Profile.UserAgent;

string json = string.Empty;
List<object> list = new List<object>();
list.Add(new []{ new{chatId = "[email protected]",message = "Hello!"}});
json = Global.ZennoLab.Json.JsonConvert.SerializeObject(list);

string response = ZennoPoster.HTTP.Request(
  method: ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.POST,
  url: url,
  content: json,
  contentPostingType: "application/json; charset=utf-8",
  proxy: proxy,
  Encoding: "UTF-8",
  respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
  Timeout: 30000,
  Cookies: string.Empty,
  UserAgent: UserAgent,
  UseRedirect: true,
  MaxRedirectCount: 5,
  UseOriginalUrl: true,
  throwExceptionOnError: true,
  removeDefaultHeaders: true
);
return response;
 

maxim.gutareff

Пользователь
Регистрация
27.01.2018
Сообщения
240
Благодарностей
16
Баллы
18
Примерно так, если json должен быть такой:
JSON:
[[{"chatId":"[email protected]","message":"Hello!"}]]
C#:
string token = "PtuFw4ENgxUZXd3884c4d026a76ec951c0ea89dfbad52";
string url = string.Format("https://app.api-messenger.com/sendmessage?token={0}",token );
string proxy = "";
string UserAgent = project.Profile.UserAgent;

string json = string.Empty;
List<object> list = new List<object>();
list.Add(new []{ new{chatId = "[email protected]",message = "Hello!"}});
json = Global.ZennoLab.Json.JsonConvert.SerializeObject(list);

string response = ZennoPoster.HTTP.Request(
  method: ZennoLab.InterfacesLibrary.Enums.Http.HttpMethod.POST,
  url: url,
  content: json,
  contentPostingType: "application/json; charset=utf-8",
  proxy: proxy,
  Encoding: "UTF-8",
  respType:ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
  Timeout: 30000,
  Cookies: string.Empty,
  UserAgent: UserAgent,
  UseRedirect: true,
  MaxRedirectCount: 5,
  UseOriginalUrl: true,
  throwExceptionOnError: true,
  removeDefaultHeaders: true
);
return response;

Но код не отправляет( Срабатывает но не отправляет. Можно ваш телеграм? Я готов платить за консультации.
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)