Php message to another server and then return another server response

I have several servers that work together.

  • Server A gives an xml response to the messages that come in.
  • Server B accepts the post request, slightly changes the message values, and then sends it to server A (adapter template). Server B must wait for the xml server to respond and then return a response.

Is there an easy way to do this with php built-in functions?

+6
source share
2 answers

I had a similar need for one of my scripts, and I was able to do this using the following,

 $url = URL_TO_RECEIVING_PHP; $fields = array( 'PARAM1'=>$_POST['PARAM1'], 'PARAM2'=>$_POST['PARAM2'] ); $postvars=''; $sep=''; foreach($fields as $key=>$value) { $postvars.= $sep.urlencode($key).'='.urlencode($value); $sep='&'; } $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $result = curl_exec($ch); curl_close($ch); echo $result; 

It will display what is returned from your receiving PHP.

+12
source

Take a look at cURL: http://php.net/manual/en/book.curl.php

This should allow you to modify the $ _POST array, send the changed values ​​to another server, and process the response.

Also see here: PHP: send a POST request, then read the XML response ,

+1
source

Source: https://habr.com/ru/post/956427/


All Articles