Viewed   62 times

I would like to know how to send a post request in curl and get the response page.



What about something like this :

$ch = curl_init();
$curlConfig = array(
    CURLOPT_URL            => "",
    CURLOPT_POST           => true,
    CURLOPT_POSTFIELDS     => array(
        'field1' => 'some date',
        'field2' => 'some other data',
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);

// result sent by the remote server is in $result

For a list of options that can be used with curl, you can take a look at the page of curl_setopt.

Here, you'll have to use, at least :

  • CURLOPT_POST : as you want to send a POST request, and not a GET
  • CURLOPT_RETURNTRANSFER : depending on whether you want curl_exec to return the result of the request, or to just output it.
  • CURLOPT_POSTFIELDS : The data that will be posted -- can be written directly as a string, like a querystring, or using an array

And don't hesitate to read the curl section of the PHP manual ;-)

Saturday, September 24, 2022

cURL is not able to verify the authenticity of the certificate being used, because the certificate for the signing authority cannot be found in the local database.

This might be symptomatic of a self signed certificate being used.

What you should do is add the certificate for the signing authority to /etc/ssl/certs/ca-certificates.crt.

What you can do is use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);, which will disable the check that is failing.

You really should use the first option.

Wednesday, August 31, 2022

you should check examples from here

Bellow is the code for you case,

$url = "";     
$data = "POST_RESULTS=true&RUN_ID=".$testrun_id."&CHECK_NAME=SampleAutomatedPlan";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 

// $output contains the output string
$output = curl_exec($ch);

// close curl resource to free up system resources
Saturday, October 15, 2022

The correct way of doing this is to simply add the content after the URL:

c = Curl::Easy.http_post("", json_string_goes_here   
    ) do |curl|
      curl.headers['Accept'] = 'application/json'
      curl.headers['Content-Type'] = 'application/json'
      curl.headers['Api-Version'] = '2.2'

This will set the json_string to be the request body.

Saturday, October 22, 2022

You can use this function:

function post(url, data, headers, success) {
        beforeSend: function(xhr){
            $.each(headers, function(key, val) {
                xhr.setRequestHeader(key, val);
            xhr.setRequestHeader('Content-Length', data.length);
        type: "POST",
        url: url,
        processData: false,
        data: data,
        dataType: "xml",
        success: success

using code like this:

var request = '<?xml version="1.0" encoding="UTF-8"?>' +
       '<entry xmlns=""' +
       '        xmlns:yt="">' +
       '    <category scheme="" term="channel"/>'+
       '    <yt:username>GoogleDevelopers</yt:username>' +

var headers = {
   'Content-Type': 'application/atom+xml',
   'Authorization': 'Bearer ACCESS_TOKEN'
   'GData-Version': 2
   'X-GData-Key': 'key=DEVELOPER_KEY'

post('/some/url', request, headers, function(response) {
Friday, October 21, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :