Trying to send a POST request using php, No matter what i do i get “HTTP ERROR 500”

后端 未结 2 1162
名媛妹妹
名媛妹妹 2021-01-28 12:08

To make an HTTP request, someone suggested I try using PHP and gave me a piece of code to work on:

$url = \'https://example.com/dashboard/api\';
$data = array(\'         


        
相关标签:
2条回答
  • 2021-01-28 12:42
          $url = 'https://domainname.com/dashboard/api';
          $params = array('to' => PHONE_NUMBER, 'from' => SENDER_ID, 'message' => TEXT, 'email' => EMAIL, 'api_secret' => SECRET, 'unicode' => BOOLEAN, 'id' => IDENTIFIER);      
          $query_content = http_build_query($params);
          $context = stream_context_create([
              'http' => [
                  'header'  => [
                       'Content-type: application/x-www-form-urlencoded',
                       'Content-Length: ' . strlen($query_content)
                  ],
              'method'  => 'POST',
              'content' => $query_content
            ]
          ]);
          $result = file_get_contents($url, false, $context);
    
    0 讨论(0)
  • 2021-01-28 12:43
    $url = 'https://domainname.com/dashboard/api';
    $header = [
        'Content-type: application/x-www-form-urlencoded',
    ];
    $params = array('to' => PHONE_NUMBER, 'from' => SENDER_ID, 'message' => TEXT, 'email' => EMAIL, 'api_secret' => SECRET, 'unicode' => BOOLEAN, 'id' => IDENTIFIER);
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL,$url);
    curl_setopt($c, CURLOPT_POST, true);
    curl_setopt($c, CURLOPT_POSTFIELDS, $params);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($c, CURLOPT_HTTPHEADER, $header);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    $res = curl_exec($c);
    var_dump($res);
    
    0 讨论(0)
提交回复
热议问题