curl post method code example

Example 1: curl post request

curl -d "user=user1&pass=abcd" -X POST https://example.com/login

Example 2: curl post json

curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data

Example 3: curl pass data in request

curl -d "param1=value1¶m2=value2" -X POST http://localhost:3000/data

Example 4: curl post request

$data = [
				'api_key' => '123456789',
				'name' => 'Emmanuel',
				'email'   => '[email protected]'
				];
			$url = 'https://mysite.com/api/subscribe';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
			$response = curl_exec($ch);
			var_export($response);

Tags:

Java Example