Magento 2 curl POST with JSON body The 2019 Stack Overflow Developer Survey Results Are InMagento 2: What Determines if a Request is “Full Page Cacheable”curl and json approve conversion Rest APIMagento 2.1: Do we need to do anything special for the controll action to accept HTTP Post with Json Payload?Magento 2 Rest api POST JSON TypeProcessor errorMagento 2 - How to apply custom function on admin grid columnMagento 2 curl send header with responseHow to get coupon times used with coupon code using REST Api?cURL with Magento 2Consumer is not authorized to access %resources selfGetting raw request body in controller
Have you ever entered Singapore using a different passport or name?
Can one be advised by a professor who is very far away?
Is "plugging out" electronic devices an American expression?
Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?
How are circuits which use complex ICs normally simulated?
Resizing object distorts it (Illustrator CC 2018)
Falsification in Math vs Science
Is there any way to tell whether the shot is going to hit you or not?
Can a rogue use sneak attack with weapons that have the thrown property even if they are not thrown?
Can we generate random numbers using irrational numbers like π and e?
Why do we hear so much about the Trump administration deciding to impose and then remove tariffs?
Why do UK politicians seemingly ignore opinion polls on Brexit?
What to do when moving next to a bird sanctuary with a loosely-domesticated cat?
What do the Banks children have against barley water?
How to manage monthly salary
Can a flute soloist sit?
How to support a colleague who finds meetings extremely tiring?
How to notate time signature switching consistently every measure
What does ひと匙 mean in this manga and has it been used colloquially?
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Does the shape of a die affect the probability of a number being rolled?
What tool would a Roman-age civilization have for the breaking of silver and other metals into dust?
Identify boardgame from Big movie
The difference between dialogue marks
Magento 2 curl POST with JSON body
The 2019 Stack Overflow Developer Survey Results Are InMagento 2: What Determines if a Request is “Full Page Cacheable”curl and json approve conversion Rest APIMagento 2.1: Do we need to do anything special for the controll action to accept HTTP Post with Json Payload?Magento 2 Rest api POST JSON TypeProcessor errorMagento 2 - How to apply custom function on admin grid columnMagento 2 curl send header with responseHow to get coupon times used with coupon code using REST Api?cURL with Magento 2Consumer is not authorized to access %resources selfGetting raw request body in controller
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
i've tried to do some curl post to my other services using built in magento curl.
i already did this for the curl request
$this->curl->post($url, $data);
yeah it's work but my data is change to url encoded style. my question is there any ways for me change the style from url encoded to Json Body request?
thanks in advance
magento2 curl
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
i've tried to do some curl post to my other services using built in magento curl.
i already did this for the curl request
$this->curl->post($url, $data);
yeah it's work but my data is change to url encoded style. my question is there any ways for me change the style from url encoded to Json Body request?
thanks in advance
magento2 curl
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
i've tried to do some curl post to my other services using built in magento curl.
i already did this for the curl request
$this->curl->post($url, $data);
yeah it's work but my data is change to url encoded style. my question is there any ways for me change the style from url encoded to Json Body request?
thanks in advance
magento2 curl
i've tried to do some curl post to my other services using built in magento curl.
i already did this for the curl request
$this->curl->post($url, $data);
yeah it's work but my data is change to url encoded style. my question is there any ways for me change the style from url encoded to Json Body request?
thanks in advance
magento2 curl
magento2 curl
asked Mar 20 '17 at 7:22
Semmi VerianSemmi Verian
485
485
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ yesterday
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Eventually it's worked using the basic Curl without using the magento curl
i am following this link https://stackoverflow.com/questions/21271140/curl-and-php-how-can-i-pass-a-json-through-curl-by-put-post-get
and it works beautifully
add a comment |
This happens when you make a curl request through magento:
vendor/magento/framework/HTTP/Client/Curl.php
protected function makeRequest($method, $uri, $params = [])
{
$this->_ch = curl_init();
$this->curlOption(CURLOPT_URL, $uri);
if ($method == 'POST')
$this->curlOption(CURLOPT_POST, 1);
$this->curlOption(CURLOPT_POSTFIELDS, http_build_query($params));
elseif ($method == "GET")
$this->curlOption(CURLOPT_HTTPGET, 1);
else
$this->curlOption(CURLOPT_CUSTOMREQUEST, $method);
...
http_build_query
corrupts the format of the json.
If you patiently read the function makeRequest(), you will be surprised that it is not possible to send json in the body or do PUT / DELETE / PATCH ... etc with params. Instead you can use the old one known
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://.../');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['a'=>'1', 'b'=>'2']));
$result = curl_exec($ch);
curl_close($ch);
if ($result === false)
return false;
else
return $result;
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f165122%2fmagento-2-curl-post-with-json-body%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Eventually it's worked using the basic Curl without using the magento curl
i am following this link https://stackoverflow.com/questions/21271140/curl-and-php-how-can-i-pass-a-json-through-curl-by-put-post-get
and it works beautifully
add a comment |
Eventually it's worked using the basic Curl without using the magento curl
i am following this link https://stackoverflow.com/questions/21271140/curl-and-php-how-can-i-pass-a-json-through-curl-by-put-post-get
and it works beautifully
add a comment |
Eventually it's worked using the basic Curl without using the magento curl
i am following this link https://stackoverflow.com/questions/21271140/curl-and-php-how-can-i-pass-a-json-through-curl-by-put-post-get
and it works beautifully
Eventually it's worked using the basic Curl without using the magento curl
i am following this link https://stackoverflow.com/questions/21271140/curl-and-php-how-can-i-pass-a-json-through-curl-by-put-post-get
and it works beautifully
edited May 23 '17 at 12:37
Community♦
1
1
answered Mar 20 '17 at 9:08
Semmi VerianSemmi Verian
485
485
add a comment |
add a comment |
This happens when you make a curl request through magento:
vendor/magento/framework/HTTP/Client/Curl.php
protected function makeRequest($method, $uri, $params = [])
{
$this->_ch = curl_init();
$this->curlOption(CURLOPT_URL, $uri);
if ($method == 'POST')
$this->curlOption(CURLOPT_POST, 1);
$this->curlOption(CURLOPT_POSTFIELDS, http_build_query($params));
elseif ($method == "GET")
$this->curlOption(CURLOPT_HTTPGET, 1);
else
$this->curlOption(CURLOPT_CUSTOMREQUEST, $method);
...
http_build_query
corrupts the format of the json.
If you patiently read the function makeRequest(), you will be surprised that it is not possible to send json in the body or do PUT / DELETE / PATCH ... etc with params. Instead you can use the old one known
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://.../');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['a'=>'1', 'b'=>'2']));
$result = curl_exec($ch);
curl_close($ch);
if ($result === false)
return false;
else
return $result;
add a comment |
This happens when you make a curl request through magento:
vendor/magento/framework/HTTP/Client/Curl.php
protected function makeRequest($method, $uri, $params = [])
{
$this->_ch = curl_init();
$this->curlOption(CURLOPT_URL, $uri);
if ($method == 'POST')
$this->curlOption(CURLOPT_POST, 1);
$this->curlOption(CURLOPT_POSTFIELDS, http_build_query($params));
elseif ($method == "GET")
$this->curlOption(CURLOPT_HTTPGET, 1);
else
$this->curlOption(CURLOPT_CUSTOMREQUEST, $method);
...
http_build_query
corrupts the format of the json.
If you patiently read the function makeRequest(), you will be surprised that it is not possible to send json in the body or do PUT / DELETE / PATCH ... etc with params. Instead you can use the old one known
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://.../');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['a'=>'1', 'b'=>'2']));
$result = curl_exec($ch);
curl_close($ch);
if ($result === false)
return false;
else
return $result;
add a comment |
This happens when you make a curl request through magento:
vendor/magento/framework/HTTP/Client/Curl.php
protected function makeRequest($method, $uri, $params = [])
{
$this->_ch = curl_init();
$this->curlOption(CURLOPT_URL, $uri);
if ($method == 'POST')
$this->curlOption(CURLOPT_POST, 1);
$this->curlOption(CURLOPT_POSTFIELDS, http_build_query($params));
elseif ($method == "GET")
$this->curlOption(CURLOPT_HTTPGET, 1);
else
$this->curlOption(CURLOPT_CUSTOMREQUEST, $method);
...
http_build_query
corrupts the format of the json.
If you patiently read the function makeRequest(), you will be surprised that it is not possible to send json in the body or do PUT / DELETE / PATCH ... etc with params. Instead you can use the old one known
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://.../');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['a'=>'1', 'b'=>'2']));
$result = curl_exec($ch);
curl_close($ch);
if ($result === false)
return false;
else
return $result;
This happens when you make a curl request through magento:
vendor/magento/framework/HTTP/Client/Curl.php
protected function makeRequest($method, $uri, $params = [])
{
$this->_ch = curl_init();
$this->curlOption(CURLOPT_URL, $uri);
if ($method == 'POST')
$this->curlOption(CURLOPT_POST, 1);
$this->curlOption(CURLOPT_POSTFIELDS, http_build_query($params));
elseif ($method == "GET")
$this->curlOption(CURLOPT_HTTPGET, 1);
else
$this->curlOption(CURLOPT_CUSTOMREQUEST, $method);
...
http_build_query
corrupts the format of the json.
If you patiently read the function makeRequest(), you will be surprised that it is not possible to send json in the body or do PUT / DELETE / PATCH ... etc with params. Instead you can use the old one known
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://.../');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['a'=>'1', 'b'=>'2']));
$result = curl_exec($ch);
curl_close($ch);
if ($result === false)
return false;
else
return $result;
answered Oct 1 '18 at 20:06
Jean Paul CPJean Paul CP
664
664
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f165122%2fmagento-2-curl-post-with-json-body%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown