这对我有用,使用\ Drupal :: httpClient()POST发送XML文件
$endpoint = 'http://example.com/something';
$xml = '<>'; // You're XML here.
// Make the request.
$options = [
'connect_timeout' => 30,
'debug' => true,
'headers' => array(
'Content-Type' => 'text/xml',
),
'body' => $xml,
'verify'=>true,
];
try {
$client = \Drupal::httpClient();
$request = $client->request('POST',$endpoint,$options);
}
catch (RequestException $e){
// Log the error.
watchdog_exception('custom_modulename', $e);
}
$responseStatus = $request->getStatusCode();
$responseXml = $request->getBody()->getContents();
希望这可以帮助。
有关Guzzle的更多信息,请访问:http ://docs.guzzlephp.org/en/latest/index.html