Jump to content

Sending POST Requests in WHMCS Dev


Dreza

Recommended Posts

I am trying to send a post request in my dev environment to the staging API of an external company. I have tried sending POST requests to a completely different URL and it doesn't work either.  So my question is, does WHMCS Dev not allow sending of POST requests and if it does can someone help me figure out why it is not working. Below is an example of how I have been trying to send the curl post request.

$ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            "Authorization: $apikey",
            "content-type: application/json",
            "Accept: application/json"
        ]);
        $curl_data = curl_exec($ch);

I also wanted to note that there is no problem with sending GET requests.

Link to comment
Share on other sites

POSTs work fine within WHMCS -- use them all the time for server actions, getting stuff from other APIs, etc.

What's the HTTP code being returned?  You can use

$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

to get that and successful requests should always be 200 .

Next, get the curl error number and text via:

$curl_error_number = curl_errno($ch);
$curl_error_text = curl_error($ch)
Once you have that information, you can move on to what to do next.  For POSTs, you are more likely to hit web filters / modsecurity rules and so you will likely see a 403 http code being returned.  

 

Link to comment
Share on other sites

On 4/28/2021 at 11:29 PM, steven99 said:

POSTs work fine within WHMCS -- use them all the time for server actions, getting stuff from other APIs, etc.

What's the HTTP code being returned?  You can use


$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

to get that and successful requests should always be 200 .

Next, get the curl error number and text via:


$curl_error_number = curl_errno($ch);
$curl_error_text = curl_error($ch)

Once you have that information, you can move on to what to do next.  For POSTs, you are more likely to hit web filters / modsecurity rules and so you will likely see a 403 http code being returned.  

 

I did what you suggested and I get the following:

http code: 500

error num: 0

error text: ''

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated