Making a POST via Curl

Could anyone please tell me what am I doing wrong here while sending the serialized data via POST using curl below:

$urlTest = ‘http://localhost:9090/JAXRS_POST_Request/rest/Request/insertDataToDB’;

	$rCURL = curl_init();
	curl_setopt($rCURL, CURLOPT_CUSTOMREQUEST, "POST"); 
	curl_setopt($rCURL, CURLOPT_POSTFIELDS, $_POST["myData"]);
	curl_setopt($rCURL, CURLOPT_URL, $urlTest);
	curl_setopt($rCURL, CURLOPT_HEADER, 0);
	curl_setopt($rCURL, CURLOPT_RETURNTRANSFER, 1);
	$response_post = curl_exec($rCURL);
	curl_close($rCURL);

$_POST["mydata"] contains the following :

[{ "name": "FirstName", "value": "Mickey" }, { "name": "LastName", "value": "Mouse" }]

I have tested the webservice by sending request separately via POSTMAN client and it works there.

In post man you can export the request to a php curl call. Do that and compare with what you have written here. Postman provides a lot of options for exporting calls to various languages.

That’s a good point. Do you know how I can convert a POST request (that I am already running on POSTMAN) to Curl based request?

I saw the import option there and saw some articles online explaining CURL to POSTMAN. Could’t find anything where my existing request can be converted to curl based request.

Thanks

Is this what @zookeeper was talking about above? It seems that postman will do it for you: https://www.getpostman.com/docs/v6/postman/sending_api_requests/generate_code_snippets

I was referring to what @droopsnoot is referring to.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.