Dreza Posted April 28, 2021 Share Posted April 28, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted April 28, 2021 Share Posted April 28, 2021 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. 0 Quote Link to comment Share on other sites More sharing options...
altomarketing Posted April 29, 2021 Share Posted April 29, 2021 Nice ! 0 Quote Link to comment Share on other sites More sharing options...
Dreza Posted April 30, 2021 Author Share Posted April 30, 2021 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: '' 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.