Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP curl request not working

rednas

New Coder
Hello,
I am trying to make a curl request with PHP to a webhook of Home Assistant.
Making this request from reqbin.com does work and I can copy the PHP code from reqbin.com. But when I copy this to my own website, it doesn't work.
This is my code (from reqbin.com):
PHP:
$url = "https://XXXX.duckdns.org:8123/api/webhook/webhook_test";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "Content-Type: application/x-www-form-urlencoded",
   "Content-Length: 0",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);

And this returns:
Code:
bool(false)

I don't know what I'm doing wrong, do you?
 
I think curl has a function go get a detailed error message when something fails. That might be a better approach than trying to guess what is going wrong.
Out of interest, does PHP not have built-in HTTP support ? I'm a bit surprised you need curl for it.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom