Versiones comparadas

Clave

  • Se ha añadido esta línea.
  • Se ha eliminado esta línea.
  • El formato se ha cambiado.

...

...

...

  •  
Tabla de contenidos

What is Postman

  •  

Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and stPostman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.reamline collaboration so you can create better APIs—faster.

How to get Postman

Postman can be found at https://www.postman.com and you can register by email or sign up with google but this step is quite optional. The application is available both on web platform https://web.postman.co/home or downloadable application https://www.postman.com/downloads

Enable SOAP and open port

First things first we have to enable the SOAP in worldserver.conf to allow remote connectivity.

If port 7878 is already in use, use another port.

Bloque de código
#    SOAP.Enable
#        Description: Enable soap service.
#        Default:     0 - (Disabled)
#                     1 - (Enabled)

SOAP.Enabled = 1

#
#    SOAP.IP
#        Description: Bind SOAP service to IP/hostname.
#        Default:     "127.0.0.1" - (Bind to localhost)

SOAP.IP = "0.0.0.0"

#
#    SOAP.Port
#        Description: TCP port to reach the SOAP service.
#        Default:     7878

SOAP.Port = 7878

After saving the modifications and worldserver has been restarted, we have to check if the port is open.

Here are a few articles telling you how to open ports for:

Windows: https://www.windowscentral.com/how-open-port-windows-firewall

Linux: https://www.journaldev.com/34113/opening-a-port-on-linux

Mac: https://www.macworld.co.uk/how-to/how-open-specific-ports-in-os-x-1010-firewall-3616405/

Here is a tool to check if the port is open https://www.yougetsignal.com/tools/open-ports

Send commands with Postman

Open Postman on Web or Desktop app and click on Import at the top left screen then switch to Raw text tab and paste the following code:

Bloque de código
languagejson
{
  "info": {
    "_postman_id": "d046fd28-e3d1-4604-a184-ce0908927991",
    "name": "TC SOAP",
    "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
  },
  "item": [
    {
      "name": "server info",
      "id": "cc5f57e1-a097-4b8f-aaea-c96ae84c1793",
      "request": {
        "auth": {
          "type": "basic",
          "basic": {
            "username": "CHANGEME",
            "password": "CHANGEME",
            "showPassword": false
          }
        },
        "method": "POST",
        "header": [],
        "body": {
          "mode": "raw",
          "raw": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"urn:TC\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n    <SOAP-ENV:Body>\r\n        <ns1:executeCommand>\r\n            <command>server info</command>\r\n        </ns1:executeCommand>\r\n    </SOAP-ENV:Body>\r\n</SOAP-ENV:Envelope>",
          "options": {
            "raw": {
              "language": "xml"
            }
          }
        },
        "url": "http://127.0.0.1:7878"
      },
      "response": []
    }
  ]
}

A new collection will appear in the left side list called TC SOAP.

To change the address, port, username, and password, click on TC SOAP > server info > Authorization

Edit by the following image the following fields: address, username, password then click on Send.

...

You should get a response back regarding the server info command down below.

...

To change the command click on Body > Raw

...

Generating code for any programming language

This is quite simple as you have to click on Code underneath the Send button.

...

Then select the programming language.

...

Keep in mind that the authorization key is a base64 encoded string of “username:password” concatenation.

PHP script code example

Here is a PHP code example (using cUrl and Soap extensions):

Bloque de código
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'http://127.0.0.1:7878',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:TC" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:executeCommand>
            <command>server info</command>
        </ns1:executeCommand>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Basic Y2hhbmdlbWU6Y2hhbmdlbWU=',
    'Content-Type: application/xml'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

The above code was generated with postman application and was tested on webhost cpanel, and on localhost xampp.

'Authorization: Basic Y2hhbmdlbWU6Y2hhbmdlbWU=', the authorization key is an encoded base64 string of account:password combination.

If you encounter a blank page and no command was sent to your server it means that the webhost is blocking outgoing port 7878.

I had to contact my webhost support to open outgoing port 7878 in order for this script to work.