ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / HTTP functions
  • Running an HTTP request with POST parameters
  • Performing a search on the different search engines
  • Calling an HTTP request
HTTPRequest (Example)
Running an HTTP request with POST parameters
WEBDEV - Server codePHPAjax
The following code os used to run an HTTP request by passing parameters in POST.
sRequestUrl is string
sRequestUrl "http://faq.pcsoft.fr/webdev22/faqsearch.awp"

// Post parameters
sPostParameter is string
sPostParameter = StringBuild("search=%1&product=%2", "WDLog", "WINDEV") 

// Request
IF HTTPRequest(sRequestUrl, "", "", sPostParameter) = True THEN
Info("Request OK, result: ", ...
HTMLToText(HTTPGetResult(httpResult)))
ELSE
Error(ErrorInfo())
END
Performing a search on the different search engines
WEBDEV - Server codePHPAjax
The following code is used to perform a search on the different Internet search engines.
// URL that must be queried
sURL is string

// Parameters to pass (in "get")
sParameters is string

// Result of the request
sResult is string

// Value that must be found by the engine
sSearchValue is string

// Name of the "agent": "Mozilla/4.0...." to simulate IE
sAgentName is string = "Mozilla/4.0 (compatible; MSIE 6.0; Win32)"
sSearchValue = "PCSOFT WINDEV WEBDEV"
// Replace the space characters by +
sSearchValue = Replace(sSearchValue, " ", "+")
// OR replace the space characters by %20
// GOOGLE case:
// sURL = "http://www.google.com/search"
// sParameters=StringBuild("q=%1&start=0", sSearchValue)
// DIR case
// sURL = "http://www.dir.com/cgi/search"
// sParameters = StringBuild("qry=%1&submit=New+search", ...
//  sSearchValue) + CR
// NOMADE case
// sURL = "http://search.nomade.tiscali.fr/search.asp"
// sParameters=StringBuild("MT=%1t&s=%1&opt=0", sSearchValue)
// YAHOO case
// sURL = "http://fr.search.yahoo.com/search/fr"
// sParameters=StringBuild("p=%1&n=10", sSearchValue)+CR
// Retrieve the result page further to an HTTP request
// with the parameters in command line 
IF HTTPRequest(sURL+"?" + sParameters, sAgentName) = False THEN
Error(ErrorInfo())
ELSE
// To view the result in an HTML control
sResult = HTTPGetResult(httpResult)
TEXTCTRL = sResult
HTMLCTRL = sResult
// Don't assign the URL to the HTML control,
// but the HTML code only. 
// Therefore, the "current" directory is not the site directory
// The images and the scripts will not be found
END
Calling an HTTP request
WEBDEV - Server codePHPAjax
The following code is used to retrieve an image from "www.windev.com". This image will be saved in the "C:\MyImages\Images.GIF" file.
// Define the variables
ResCall is boolean
FileID is int 

// Open the "C:\MyImages\Images.GIF" file
FileID = fOpen("C:\MyImages\Images.GIF", foCreate)
IF FileID <> -1 THEN
// Retrieve the image
ResCall = HTTPRequest("http://www.windev.com/img/decor/block-t-l.gif")
IF ResCall = True THEN
// Save the image in the file
fWrite(FileID, HTTPGetResult(), ...
Length(HTTPGetResult())
END
// Close the file
fClose(FileID)
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 09/06/2023

Send a report | Local help