Created
August 13, 2022 12:07
-
-
Save Tonel/84f39dc7d1690a9ff91ffc32e6745519 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$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