The correct way to submit (POST) xml with guzzle 6

I want to record with gzzle sending xml file. I did not find an example.

What i have done so far:

$xml2=simplexml_load_string($xml) or die("Error: Cannot create object"); use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; $client = new Client(); // $request = new Request('POST', $uri, [ 'body'=>$xml]); $response = $client->send($request); // //$code = $response->getStatusCode(); // 200 //$reason = $response->getReasonPhrase(); // OK // echo $response->getBody(); 

No matter what I try, I return a -1 error, which means the xml is invalid. The XML I'm submitting is being tested online, although it is valid% 100

Please, help.

+7
xml php guzzle guzzle6
source share
4 answers

After some experimentation, I realized this. Here is my solution if someone reaches a dead end.

 $request = new Request( 'POST', $uri, ['Content-Type' => 'text/xml; charset=UTF8'], $xml ); 
+12
source share

If you want to send xml using the post method, here is an example:

 $guzzle->post($url, ['body' => $xmlContent]); 
+2
source share

This is what worked for me on Guzzle 6:

 $Options = [ 'headers' => [ 'ContentT-ype' => 'text/xml; charset=UTF8', ], 'body' => $XML, ]; $Response = $Client->request('POST',$Url,$Options); 
+2
source share

Try publishing data such as:

 $xml2=simplexml_load_string($xml) or die("Error: Cannot create object"); use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; $client = new Client(); // $request = new Request('POST', $uri, [ 'form_params' => [ 'xml' => $xml, ] ]); $response = $client->send($request); //$code = $response->getStatusCode(); // 200 //$reason = $response->getReasonPhrase(); // OK echo $response->getBody(); 
-2
source share