PHP $_POST to retrieve application/x-www-form-urlencoded i.e form submission post request
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_POST['fname'];
}
CURL for Content-Type:application/x-www-form-urlencoded
curl -i \
-H "content-type:application/x-www-form-urlencoded" \
-d 'fname=test' \
-X POST http://server:port \
--trace-ascii /dev/stdout
https://stackoverflow.com/questions/52320831/curl-send-json-as-x-www-form-urlencoded/52320948
https://www.w3schools.com/php/php_superglobals_post.asp
PHP file_get_contents('php://input') to retrieve content-type:application/json i.e API post request
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE); //convert JSON into array
CURL for Content-Type:application/jsoncurl -i \
-H "content-type:application/json" \
-d '{"email":"customerA@hotmail.com", "name":"customerA", "message": "Hi there, just love your website"}' \
-X POST http://ip:port \
--trace-ascii /dev/stdout
https://stackoverflow.com/questions/52320831/curl-send-json-as-x-www-form-urlencoded/52320948
No comments:
Post a Comment