I am trying to post XML request to ingram micro url the code shown below
<?php
$url = "https://newport.ingrammicro.com/mustang";
$post_string = '<BaseRateRequest>
<Version1.0></Version1.0>
<TransactionHeader>
<CountryCode>FT</CountryCode>
<LoginID>username</LoginID>
<Password>password</Password>
<TransactionID>TESTAIC12356</TransactionID>
</TransactionHeader>
<BaseRateInformation>
<BranchOrderNumber>4066000</BranchOrderNumber>
<PostalCode>L5R1V4</PostalCode>
<Suffix />
</BaseRateInformation>
</BaseRateRequest>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "XML=".$post_string);
$data = curl_exec($ch);
print_r($data);
?>
But, I don't know how to request and response in XML. I am getting the error: Invalid Inbound XML Document.
What does that means and how to solve it ?
you have to remove "XML="
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
and probably also add the XML header:
<?xml version="1.0" encoding="UTF-8"?>
<BaseRateRequest>
...
</BaseRateRequest>
Related
I use RESTful webservice and it's show some xml.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <users>
- <user>
<id>1</id>
<name>Mahesh</name>
<profession>Teacher</profession>
</user>
</users>
I want to add new xml, send to the webservice.
$xml =
'<users>
<user>
<id>3</id>
<name>hangga</name>
<profession>IT</profession>
</user>
</users>';
Here my php code :
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://localhost:18080/UserManagement/rest/UserService/users");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); //setting content type header
curl_setopt($curl, CURLOPT_POST, $xml);//Setting raw post data as xml
$result = curl_exec($curl);
curl_close($curl);
print($result);
But nothing happens, web service not show new XML. My question how to add new xml and send it to web service using php? should I use cUrl? is there another way? I really need help, the answer will very appreciated. Thanks all
$url = 'http://webservice/example/user';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/xml',
'Content-Length: ' . strlen($data))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$responses = curl_exec($ch);
curl_close($ch);
I have to invoke a soap web service using curl and php.
I tried this code:
$ch = curl_init();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd................</soapenv:Envelope>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
This code works well but I can't to print the result as XML.
If I use other client to invoke the same service I obtain a XML response (this is correct). Why?
I need to send the following request, which is XML with a username and password on the end of the xml. I can get this to work as a URL when I paste into the browser:
URL?XML=<>...</>&user=123456&password=123456
But when I try to create the curl call it says it's an invalid XML request.
I've tried having the user&password within the POSTFIELDS. I've also tried setting them as a variable before $trial ='&user=123456&password=123456' but still can't seem to get it to work.
$xml = <<<ENDOFXML
<?xml version="1.0" encoding="UTF-8"?><xmldata>...</xmldata>
ENDOFXML;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml).urlencode('&user=123456&password=123456'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_close($ch);
This is wrong:
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml).urlencode('&user=123456&password=123456'));
urlencode only the variable names and the values (or only values if you know the variable names are ok):
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xml='.urlencode($xml).'&user=' . urlencode('123456').'&password=' . urlencode('123456'));
Here my code is,
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close ($ch);
print_r($response);
I got response like this
<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="ok">
<mediaid>af11zj</mediaid>
<mediaurl>http://yfrog.com/af11zj</mediaurl>
</rsp>
How to get that mediaurl ? Any one help me? Thanks.
Assume you have the response XML in $response:
<?php
$obj = simplexml_load_string($response);
$mediaurl = (string) $obj->mediaurl;
?>
I need to receive xml data from server.
Allowed only two methods to send data to server "GET" AND "PUT"
POST method- is no allowed.
My code is
<?php
set_time_limit(0);
ini_set('display_errors','1');
error_reporting(E_ALL);
$url = 'https://url is here..';
$fp = fopen(getcwd() . "/ping.xml", "r+");
// Initialize session and set URL.
$ch = curl_init();
//curl_setopt($ch, CURLOPT_URL, $url.'?xml='.$xml);
curl_setopt($ch, CURLOPT_URL, $url);
//GET
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_FILE, $fp);
//curl_setopt($ch, CURLOPT_INFILE, $fp);
//curl_setopt($ch, CURLOPT_INFILESIZE, filesize(getcwd() . "/ping.xml"));
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_SSLVERSION, 3 );
curl_setopt($ch, CURLOPT_VERBOSE, '1');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLCERT, getcwd() . "/certs/test_lv.pem");
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "test_lv");
curl_setopt($ch, CURLOPT_SSLKEY, getcwd() . "/certs/test_lv.key");
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "test_lv");
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml','correlationId :'.date("y-m-d-h-m-s")));
curl_setopt($ch, CURLOPT_HEADER, 1);
// Get the response and close the channel.
$response = curl_exec($ch);
echo curl_error($ch);
print_r($response);
echo '<br>end';
curl_close($ch);
?>
I have spent all my day connecting to the server and now it works.
I trying to send xml file as Put method
Xml file data:
<?xml version="1.0" encoding="UTF-8"?>
<Ping>
<Value>Test</Value>
</Ping>
Its not work I have this error:
HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server Error Content-Length: 0 Server: Jetty(6.1.21)
end
Answers needs to be:
Received pong.xml-s
<?xml version="1.0" encoding="UTF-8"?>
<B4B xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://test.net/valid/hgw-response.xsd">
<Pong from="EE">
<Value>Test</Value>
</Pong></B4B>
Thanks for advices
P.S How can i Send xml file via GET method ..Im trying to do this
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<Ping>
<Value>Test</Value>
</Ping>';
curl_setopt($ch, CURLOPT_URL, $url.'?xml='.$xml);
It's not work too for me.