Jump to content

Help testing php/XML curl call and POST variable


cgchris99

Recommended Posts

Ok, I need to make a PHP Curl request sending some XML Code. According do the API docs it must be in a field called data.

 

When I make the request it says no data. So I thought I would test this on my own server.

I have a a file called testpostxml.php

<pre>
<?php print_r($_POST);?>
</pre>

 

The response is

Array

(

)

 

So it appears that no data is getting sent to the server except the URL. The XML data must not be going thru or the post variable is not getting set properly.

	public function sendHttpRequest($requestBody)
{
	//build eBay headers using variables passed via constructor
	$headers = $this->buildHeaders($requestBody);

	//initialise a CURL session
	$connection = curl_init();
	//set the server we are using (could be Sandbox or Production server)
	curl_setopt($connection, CURLOPT_URL, $this->serverUrl);

	//stop CURL from verifying the peer's certificate
	curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
	curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
	curl_setopt($connection, CURLOPT_USERAGENT,	"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");

	//set the headers using the array of headers
	curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);

	//set method as POST
	curl_setopt($connection, CURLOPT_POST, 1);

	//set the XML body of the request
//		curl_setopt($connection, CURLOPT_POSTFIELDS, $requestBody);
	curl_setopt($connection, CURLOPT_POSTFIELDS, 'data='.urlencode($requestBody));
	//set it to return the transfer as a string from curl_exec
	curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);

	//Send the Request
	$response = curl_exec($connection);

	//close the connection
	curl_close($connection);

	//return the response
	return $response;
}

 

Is this the best way to test out what gets sent to the URL including the post variables?

 

If anyone has advice, it would really help me out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.