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;








4















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










share|improve this question














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.





















    4















    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










    share|improve this question














    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.

















      4












      4








      4








      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










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      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.






















          2 Answers
          2






          active

          oldest

          votes


















          0














          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






          share|improve this answer
































            0














            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;






            share|improve this answer























              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
              );



              );













              draft saved

              draft discarded


















              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









              0














              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






              share|improve this answer





























                0














                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






                share|improve this answer



























                  0












                  0








                  0







                  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






                  share|improve this answer















                  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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 23 '17 at 12:37









                  Community

                  1




                  1










                  answered Mar 20 '17 at 9:08









                  Semmi VerianSemmi Verian

                  485




                  485























                      0














                      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;






                      share|improve this answer



























                        0














                        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;






                        share|improve this answer

























                          0












                          0








                          0







                          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;






                          share|improve this answer













                          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;







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Oct 1 '18 at 20:06









                          Jean Paul CPJean Paul CP

                          664




                          664



























                              draft saved

                              draft discarded
















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                              Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                              Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?