Search code examples
phpphp-curl

how do i punctuate php curl statements


i am not profficeint in php when i encounter the term curl.

The below code apparently needs a correction.

curl_setopt($ch, CURLOPT_POSTFIELDS, {
"ShortCode": 600981,
"ResponseType": "Completed",
"ConfirmationURL": "https://mydomainx.com/confirmation",
"ValidationURL": "https://mydomainx.com/validation",
});

It gives an error

syntax error. unexpected '{' on the very first line. I will try any help offered.


Solution

  • You can pass data as an array

    $data = json_encode(array(
        "ShortCode" => "600981",
        "ResponseType" => "Completed",
        "ConfirmationURL" => "https://mydomainx.com/confirmation",
        "ValidationURL" => "https://mydomainx.com/validation",
    ));
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);