2

enter image description here

This request requires Basic Auth: user and password.

enter image description here

Headers with two fields.

enter image description here

and xml body.

This API is tested working in Postman. But I am not sure how to make this work in Laravel, I only work with JSON before.

Any suggestion how can I get started? or any package I can use?

1 Answer 1

7

You can use http post

 $http=Http::withHeaders([ 'Content-Type'=>'application/xml', 'SOAPAction'=>'balance' ])->post(url,$xmlBodyContent); return response($http->body()) ->withHeaders([ 'Content-Type' => 'text/xml' ]); 

Another way is to use withBody method

$http=Http::withHeaders([ 'Content-Type'=>'application/xml', 'SOAPAction'=>'balance' ])->withBody($xmlBodyContent,"text/xml")->post(url); 

for xml doc notation Ref:https://www.php.net/manual/en/simplexml.examples-basic.php

To generate array to xml,use array-to-xml

Sign up to request clarification or add additional context in comments.

3 Comments

As an addition to this answer I think you should check out Spatie's array to xml package, makes a world of difference IMO github.com/spatie/array-to-xml
Works great. sabre.io/xml to write is also a great option to write XML's.
$http=Http::withHeaders([ 'Content-Type'=>'application/xml', 'SOAPAction'=>'balance' ])->withBody($xmlBodyContent,"text/xml")->post(url); This one is worked for me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.