PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Sending a file
  • Sending a form with a file to upload to a WEBDEV AWP page
  • Sending a form (HEAD method)
HTTPSendForm (Example)
Sending a file
HTTPCreateForm("FORM")
HTTPAddFile("FORM", "file[]", CompleteDirp(fExeDir) + "1File.txt", "text/plain")
HTTPAddParameter("FORM", "domain", "0")
HTTPAddParameter("FORM", "submit", "Send")
HTTPSendForm("FORM", "http://Url_to_contact, httpPost, "", ...
 "Accept: text/html, application/xhtml+xml, image/jxr; */*" + CR + ...
 "Accept-Language: en-EN" + CR)
Sending a form with a file to upload to a WEBDEV AWP page
sForm is string = "FORM"
sUrlPageAWP is string = "http://localhost/WW_MYSITE_WEB/FR/PAGE_WEBDEV_AWP.awp"

// Value to transmit
sValueName is string = "Doe"
sFile is string = "c:\My Projects\ToUpload.zip"

// Link/Button that performs the process
sNameButtonToRun is string = "LINK_VALID"
sResult is string

HTTPCreateForm(sForm)

// Data of the form in the WEBDEV page
// Edit controls of the WEBDEV page
HTTPAddParameter(sForm, "EDT_NAME", sValueName)

// Upload control
HTTPAddFile(sForm, "EDT_UPLOAD", sFile)

// Be careful with the name of WEBDEV controls:
// 1 - we must disable the compression option for the name of controls (..Alias)
// for the WEBDEV page (or project) in the Advanced tab
// 2 - the names of WEBDEV controls are always written in uppercase

// Special controls used to specify
// to the WEBDEV application server the button/link to run
HTTPAddParameter(sForm, "WD_BUTTON_CLICK_", sNameButtonToRun)
HTTPAddParameter(sForm, "WD_ACTION_", "")

// Send the form
IF HTTPSendForm(sForm, sUrlAWPPage, httpPost) = False THEN
Error("Failure sending the form: ", ErrorInfo())
ELSE
IF ExtractString(HTTPGetResult(httpHeader), 2, " ")[[1]] <>"2" THEN
Error("HTTP error:", HTTPGetResult(httpResult))
ELSE
sResult = HTTPGetResult(httpResult)
IF sResult <> "OK" THEN
Error("the form was not processed properly", ...
"encountered errors: ", sResult)
ELSE
Info("Data and file successfully sent")
END
END
END
//-------------------------------------------------------------------------
//-- Server code of the "LINK_VALID" link in the WEBDEV AWP page
//-------------------------------------------------------------------------
bufReturn is Buffer

// Check the received controls
// File to upload?
IF EDT_UPLOAD = "" THEN
//no
bufReturn += [CR] + "No file to upload"
ELSE
// Retrieve the uploaded file
// UploadCopyFile(EDT_UPLOAD....)
// Other controls of the form
IF EDT_NAME = "" THEN
// Retrieve the name ...
bufReturn += [CR] + "No NAME"
ELSE
bufReturn += [CR] + "OK"
END
END

// Response
StringDisplay(bufReturn, "text/plain")
Sending a form (HEAD method)
sSearch is string = "pcsoft"
HTTPCreateForm("Search")
HTTPAddParameter("Search", "hl", "fr")
HTTPAddParameter("Search", "q", sSearch)
HTTPAddParameter("Search", "btnL", sSearch)
HTTPAddParameter("Search", "meta", "")
IF NOT HTTPSendForm("Search", "www.google.fr/search", httpHead) THEN
Error("HTTPSendForm failed and the following error occurred: " + ErrorInfo())
ELSE
bufBres is Buffer = HTTPGetResult(httpResult)
IF Length(bufBres) > 0 THEN
Error("Result buffer")
END
END
Minimum version required
  • Version 15
This page is also available for…
Comments
Click [Add] to post a comment