I am trying to convert this cURL script to use it with PHP and Guzzle. I have been able to set the cookie as shown below but I cannot send the xml file I need to afterwards.
cURL Script
# First, we need to get the cookie
curl [-k] –dump-header <header_file> -F “action=login” -F “username=<username>” -F “password=<password>” https://<website_URL>
# Then, we can use that cookie to upload our orders
# XML Order Upload
curl -b <header_file> -F “import=@<order_file>” http://<website_URL>/importXMLOrder.php
This is what I have that sets the cookie. I am not sure what the next part is to actually send the xml file I have.
$client = new \GuzzleHttp\Client();
$response = $client->post('http://website/login.php', array(
'body' => array(
'username' => 'xxxxx',
'password' => 'xxxxxx'
))
);
I have also tried this. However, I get an error message:
Call to undefined method GuzzleHttp\Message\Response::send()
$request = $client->post('http://website.com/import.php', array(
'body' => array(
'file_filed' => fopen('orders.xml', 'r')
)));
$response = $request->send();
$data = $response->xml();
print_r($data);
Update
$request = $client->createRequest('POST','http://website.com/import.php', array(
'body' => array(
'file_filed' => file_get_contents('orders.xml', 'r')
)
));
$response = $client->send($request);
//var_dump($response); die;
$data = $response->xml();
echo '<pre>';
print_r($data);