Home > Blockchain >  XMLRPC library for API in laravel
XMLRPC library for API in laravel

Time:10-16

I want to use XMLRPC to get my API results and show them in XML format in laravel project. I've seen numerous examples for XMLRPC for PHP but can't find any for laravel yet. API i'm using is Wired wubook api: enter image description here

Any help through which I can use XMLRPC in laravel and call my API results in project?

CodePudding user response:

I used the curl method of XML in my PHP code to send XML code to Wubook server. And it worked like a charm.

$xml = "<?xml version='1.0'?>
<methodCall>
  Some YOUR XML CODE PARAMS
</methodCall>";

$url = "https://yoururl.com/";
$send_context = stream_context_create(array(
  'http' => array(
    'method' => 'POST',
    'header' => 'Content-Type: application/xml',
    'content' => $xml
  )
));
$response =  file_get_contents($url, false, $send_context);
$xml1 = simplexml_load_string($response);
$json = json_encode($xml1);
$array = json_decode($json,TRUE);
return response()->json($array);

This way I could be able to send XML code to server and get response in JSON format.

  • Related