Skip to content

Instantly share code, notes, and snippets.

@Tonel
Created August 13, 2022 12:07
Show Gist options
  • Save Tonel/84f39dc7d1690a9ff91ffc32e6745519 to your computer and use it in GitHub Desktop.
Save Tonel/84f39dc7d1690a9ff91ffc32e6745519 to your computer and use it in GitHub Desktop.
<?
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, "https://www.w3schools.com/jquery/demo_test_post.asp");
// specify that the cURL request is a POST
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// define the body of the request
curl_setopt($curl, CURLOPT_POSTFIELDS,
// http_build_query is required to simulate
// a FormData request. Ignore it on a JSON request
http_build_query(
array(
"name" => "Donald Duck",
"city" => "Duckburg"
)
)
);
// define the body of the request
curl_setopt($curl, CURLOPT_POSTFIELDS,
array(
"name" => "Donald Duck",
"city" => "Duckburg"
)
);
// replicate the AJAX call
$result = curl_exec($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment