如何使用curl编码令牌

STEP - 1

I am sending a xml request using CURL and its returning "TOKEN" to me. Please find the below code here:

<root><request><type>mykey</type><username>myusername</username><password>mypassword</password></request></root>

$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $curl_url);// passing API URL here
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $xml_strign); // passing xml as a string
$result = curl_exec ($curl_handle);

In this above code executing fine and returning Token as a result.

STEP - 2

In second step, I have to send above token to get my result but not getting result.Please find the below code:

$xml = "<root>
<request>
<type>myparam</type>
<token>lGcvdOnetuxK0paE+AIxE93GB85DURIpOeoBw8quqOs=</token>
</request>
</root>";

curl_setopt($curl_handle, CURLOPT_URL, $curl_url);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $xml);
$result = curl_exec ($curl_handle);
curl_close ($curl_handle);
print_r($result);

May be this Token is contains special charter as i guess, so that I am not getting result. I have seen console url response status in browser its 200 ok.

I do appreciate advance for your help.

I think you have a problem with your post data. You should read details about CURLOPT_POSTFIELDS here :

http://php.net/manual/fr/function.curl-setopt.php

So your xml variable should probably be defined like this:

$xml = array("token" => "lGcvdOnetuxK0paE+AIxE93GB85DURIpOeoBw8quqOs");

At least it should be an array.