-2

I have this code in PHP and I need to do it in React

$consult = new SoapClient('My webPage');    
    $response = $consult->consultJob($name,$id);

Is there an easy way to do that?

  • 1
    May be duplicated by https://stackoverflow.com/questions/124269/simplest-soap-example, have you checked this out? – TheKeymaster Mar 12 '21 at 20:20

1 Answers1

0

The PHP SoapClient is a server side action. When you say "do it in React", i'm assuming you mean the browser? So you would not typically do this in the browser directly, but in a nodejs runtime on the server using a package like soap

Their example in the docs:

var soap = require('soap');
var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};
soap.createClientAsync(url).then((client) => {
    return client.MyFunctionAsync(args);
}).then((result) => {
    console.log(result);
});
Arges86
  • 1
  • 1
  • 1
  • Thanks, but I need to do the request in the frontend – Carlos García Mar 12 '21 at 19:19
  • Well, I SOAP request is essentially a POST request with a SoapAction header, So you can just use JS fetch API and add the soapAction header to it: const headers = new Headers(); headers.append('SOAPAction', 'consultJob'); – Arges86 Mar 12 '21 at 21:58