@maiskiykot
Free coder

Как перевести curl запросы в PHP?

Наверное, выглядит вопрос ламерски, но что делать: никак не могу понять принцип перевода запросов curl в PHP, а подробные доки нигде не попадаются. Есть запрос - помогите перевести в PHP вид или хотя бы принцип тегов объясните курловых. Заранее спасибо!

curl -X POST \
 https://online.moysklad.ru/api/remap/1.1/entity/paymentin \
 -u admin@test515:123456 \
 -H 'Content-Type: application/json' \
 -H 'cache-control: no-cache' \
 -d '{
 "organization": {
 "meta": {
 "href": "https://online.moysklad.ru/api/remap/1.1/entity/organization/ff24265a-ecfd-11e8-9109-f8fc000d545b",
 "type": "organization"
 }
 },
 "agent": {
 "meta": {
 "href": "https://online.moysklad.ru/api/remap/1.1/entity/counterparty/ff255c42-ecfd-11e8-9109-f8fc000d545e",
 "type": "counterparty"
 }
 }
}'
  • Вопрос задан
  • 1269 просмотров
Пригласить эксперта
Ответы на вопрос 1
slo_nik
@slo_nik Куратор тега PHP
Доброе утро.
Есть хороший сервис.
Вот результат
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://online.moysklad.ru/api/remap/1.1/entity/paymentin");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"organization\": {\n \"meta\": {\n \"href\": \"https://online.moysklad.ru/api/remap/1.1/entity/organization/ff24265a-ecfd-11e8-9109-f8fc000d545b\",\n \"type\": \"organization\"\n }\n },\n \"agent\": {\n \"meta\": {\n \"href\": \"https://online.moysklad.ru/api/remap/1.1/entity/counterparty/ff255c42-ecfd-11e8-9109-f8fc000d545e\",\n \"type\": \"counterparty\"\n }\n }\n}");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "admin@test515" . ":" . "123456");

$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Cache-Control: no-cache";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы