Shiny Language Reference

Language Reference > Web Functions


wpost

bool wpost(web WebVar, string URL, string Params[, bool Secure, string Referrer]);

 

Synonyms:

bool webpost(web WebVar, string URL, string Params[, bool Secure, string Referrer]);
 
 

Uses HTTP POST to send data to a website

The WPOST statement simulates the posting of form data to a specific website/web page. Forms and HTTP POST are the standard method of supplying data back to a webserver, for example how Amazon.com knows what product pages to display. Detailed discussion of how HTML forms work and how posting data works is outside the scope of this reference - any good HTML book will provide plenty of detail.

WPOST directly replaces wopen when form data is posted. Under normal circumstances when a plugin wants to read data from a web page, wopen is used to create a connection to the webpage, then wreadline or wreadbytes are used to read the actual data on the page. When form data is posted WPOST should be used to create the connection to the web page and post the data, then wreadline or wreadbytes should be used to read the response data.

Note: This statement is considered stable but experimental. Please submit a bug report or feature request as required.

 

Parameters

WebVar

A variable declared as type WEB, which will be associated with the opened website and used for all access to it.

URL

The full HTTP URL to the resource to access and post data to. There is no requirement to include the "http://" protocol specifier prefix.

Params

The parameters to HTTP POST to the web server. These are usually in the format of "param=value&param2=value", for example "id=99&showdata=true&sort=down". You may take these parameters directly from your web browser.

Secure

Optional. When True, Brass attempts to establish an HTTPS connection to the specified webserver. This parameter is False by default.

Referrer

Optional. A URL specifying the "fake" referrer for the URL resource in parameter 2. Many webservers will deny access to resources unless the access request has come from another resource on that same server. For example, when you browse to a webpage all the images on that page will appear, as the referrer for the resource will be the webserver itself. However if you try to directly view one of the images your access may be denied as the referrer will be incorrect. This is a standard mechanism for webservers to deny image hotlinking. By specifying a referrer in this parameter you can usually bypass such restrictions.

 

Return Value

TRUE if opening the site suceeded, otherwise FALSE. The return value of WPOST can be used for further operations.

 

Example Code

// The following code simulates returning a set of plugins from the Brass
// website Plugins page.
web BrassSite
;
string URL = "http://www.amazingbrass.co.uk/pluginsmain.php";
string Params = "startat=5&showmax=5&orderby=date&orderas=descending";

bool Result = wopen(BrassSite, URL, Params);


if(Result == True)

{
    bool bMoreData = True;
    
    while(bMoreData)
    {
        // DataIn receives each line of text from the site
        string DataIn;
        bMoreData = wreadline(BrassSite, DataIn);

        if(strfind(DataIn, "<html>") != -1)
        {
            // The start of the HTML data has been found
        }
    }
}