HTTP Request with POST data not working

Hi, I’m trying to send an HTTP request using POST and sending data via POST.

Here is a screenshot of my settings. The URL is correct.

In the output area you can see that the PHP script does not receive any data, neither by GET, nor by POST.

I need to submit data via POST, but I don’t know how to set the HTTP Request object settings or why it doesn’t work and no data is submitted.

The POST data should be sent together with a file. To send the file I presumably need to set the ‘Body Content Type’ setting to ‘RAW/Custom’?

Thanks
René

Hi,

When using JSON/RAW Parameters, you are in control. Your Query Parameters is set as JSON, so Body Content Type should be JSON. If you want to send as a different Content-Type you’ll need to add to Options and use MIME Type.

If you are sending a file, you will want to Send Binary Data and supply the item property containing the file data. The data should be read into the workflow with the Read Binary File node.

Your PHP script doesn’t understand your request as Body Content Type: Raw/Custom doesn’t send a Content-Type header. Unless you were to set one at the PHP end, but you’re best off sending it with the request.

Additionally, Body Parameters doesn’t end up in a global PHP array ($_GET, $_POST, etc), but needs to be read from php://input or STDIN. See rest - How to get body of a POST in php? - Stack Overflow

During testing, you may find the $_REQUEST global array handy.

print_r($_REQUEST)

Hope this helps.

1 Like

You might find some of this code useful when dealing with PHP

    // Takes raw data from the request
	$json = file_get_contents('php://input');
	 // Converts it into a PHP object
	$datajson = json_decode($json);


	$data = objectToArray($datajson);





function objectToArray($d) 
{
	if (is_object($d)) {
		// Gets the properties of the given object
		// with get_object_vars function
		$d = get_object_vars($d);
	}

	if (is_array($d)) {
		/*
		* Return array converted to object
		* Using __FUNCTION__ (Magic constant)
		* for recursive call
		*/
		return array_map(__FUNCTION__, $d);
	} else {
		// Return array
		return $d;
	}
}
2 Likes

Ok thanks a lot. I’ll try my best to make it. :+1: