HTTPServer [examples]

Send an HTTP POST request to the specified URI
POSTURL
// send a soap request
responsefile = posturl("http://www.myserver.com/somewebservice.aspx", ;
                           30, ;
                           array("type" => "Content-Type: application/soap+xml", "host" => "Host: localhost"), ;
                           "requestdata.xml","response.xml")
 
// submit a form
response = posturl("http://www.myserver.com/someformsubmission.rsp", ;
                           30, ;                              
                           array("type" => "Content-Type: application/x-www-form-urlencoded"), ;
                           "name=barry&product=lianja")                                         
if len(response) = 0    
    // no data was returned
endif

https://www.lianja.com/doc/index.php/POSTURL()


Talk with HTTP web servers and consume data provided by web services
GETURL

 

filename = geturl("http://www.myserver.com/getsomepage.rsp?name=smith&month=10", 30, array(), "myfilename.json")
if len(filename) = 0
    // no data was returned
endif

https://www.lianja.com/doc/index.php/GETURL()


So while an App is running, from another App you can query it e.g.:

result = getURL("http://localhost:8002/desktopwebservice/library:/dws_getinfo?customerid=ALFKI")

The web service name follows /desktopwebservice/ in the URL and is a normal program or proc. In this case we have a script named dws_getinfo. It is good practice to name these consistently and place them in the library directory. We recommend prefixing your desktop web services with dws_.

// In this example, the URL will contain "/desktopwebservice/library:/dws_getinfo" and args will contain "customerid=ALFKI"
// dws_getInfo.prg in the library directory
private p_url
private p_arg
private p_args = explode("&", p_arg)
private p_customerid = getMember("p_args", "customerid", "")
return "{'url': '&p_url, 'customerid': '&p_customerid'}"

Your service may return a JSON encoded object (as shown above), an XML string, an HTML string or plain text.

If the result returned starts with “file:” then the file specified e.g. “file:mytempfile.txt” is read and the result is sent back to the client. This provides the ability to query large amounts of information not limited by internal string length.

If the result returned starts with “tempfile:” then the file specified e.g. “tempfile:mytempfile.txt” is read and the result is sent back to the client. The file mytempfile.txt is then deleted.

Notice that in the example above no file extension was given to dws_getinfo so “.prg” (Lianja/VFP script) is assumed. You could also specify:

result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.js?customerid=ALFKI")

or

result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.php?customerid=ALFKI")

or

result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.py?customerid=ALFKI")

or

result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.rsp?customerid=ALFKI")

or

result = getUrl("http://localhost:8002/desktopwebservice/library:/dws_getinfo.jssp?customerid=ALFKI")

https://www.lianja.com/doc/index.php/Embedded_HTTP_Server


getUrl() and postUrl()

You can use the GETURL() built-in function to talk with HTTP web servers and fetch data provided by web services.

filename = geturl("http://www.myserver.com/getsomepage.rsp?name=smith&month=10", 30, array(), "myfilename.json")
if len(filename) = 0
    // no data was returned
endif

You can use the POSTURL() built-in function to send an HTTP POST request to the specified URI.

// send a soap request
responsefile = posturl("http://www.myserver.com/somewebservice.aspx", ;
                           30, ;
                           array("type" => "Content-Type: application/soap+xml", "host" => "Host: localhost"), ;
                           "requestdata.xml","response.xml")
 
// submit a form
response = posturl("http://www.myserver.com/someformsubmission.rsp", ;
                           30, ;                              
                           array("type" => "Content-Type: application/x-www-form-urlencoded"), ;
                           "name=barry&product=lianja")                                         
if len(response) = 0    
    // no data was returned
endif

 https://www.lianja.com/doc/index.php/Web_Integration