Proper way to send (POST) xml with guzzle 6

后端 未结 2 1400
南旧
南旧 2021-02-12 16:58

I want to perform a post with guzzle sending an xml file. I did not find an example.

What I \'ve done so far is :

$xml2=simplexml_load_string($xml) or d         


        
相关标签:
2条回答
  • 2021-02-12 17:40

    This is what worked for me on Guzzle 6:

    // configure options
    $options = [
        'headers' => [
            'Content-Type' => 'text/xml; charset=UTF8',
        ],
        'body' => $xml,
    ];
    
    $response = $client->request('POST', $url, $options);
    
    0 讨论(0)
  • 2021-02-12 17:59

    After some experiments, I have figured it out. Here is my solution in case someone reaches a dead end.

    $request = new Request(
        'POST', 
        $uri,
        ['Content-Type' => 'text/xml; charset=UTF8'],
        $xml
    );
    
    0 讨论(0)
提交回复
热议问题