Using JavaScript in HomeSite 4.0, Part III: The HTTPProvider Object's Methods, Part II
Using JavaScript in HomeSite 4.0, Part III
The HTTPProvider Object's Methods, Part II
SaveReceivedStreamToFile(fileName, overwriteFlag) | String |
This method saves the received stream to a file, and overwrites an existing file if overwriteFlag
is true
. This method returns an error message upon failure. It returns "File already exists
" when the given fileName
exists and overwriteFlag
is false. It returns "Path does not exist
" when fileName
is not found.
The following script reads an html page from a server and tries to save it to a local disk:
var app = Application;
function Main() {
var app = Application;
app.HTTPProvider.URL = "https://www.webreference.com/js/tips/990923.html";
app.HTTPProvider.Get();
var errorMsg = app.HTTPProvider.SaveReceivedStreamToFile
("d:\\yehuda\\990923.html", false );
// (The above two lines should be joined as one line.
// They have been split for formatting purposes.)
if (errorMsg != "")
{
app.MessageBox("Save failed: " + errorMsg, "Save Error", 0);
}
app = null;
}
The first run of this script creates the file on the local disk. The second run will fail to overwrite the existing file because the overwriteFlag
is false
. This is the window that will pop up:
Post() | None |
Performs an HTTP POST method request.
Head() | None |
Performs an HTTP HEAD method request.
GetAsync() | None |
Performs an HTTP GET method request asynchronously.
PostAsync() | None |
Performs an HTTP POST method asynchronously.
HeadAsync() | None |
Performs an HTTP HEAD method request asynchronously.
Abort() | None |
Aborts the current HTTP operation.
URLEncode(stringValue) | String |
Converts a string to a URLEncoded format. Usefull when populating URL or FORM data.
Produced by Yehuda Shiran and Tomer Shiran
Created: October 11, 1999
Revised: October 15, 1999
URL: https://www.webreference.com/js/column50/httpmeth2.html