RSBIHttpRequest class
The class that is used to make HTTP requests. It has the same functions as the standard JavaScript object XMLHttpRequest 1.0. The latter is also supported but it is recommended to use RSBIHttpRequest.
NTLM authentication
You can specify the additional parameters in theopen()
method of
RSBIHttpRequest class to use NTLM authentication. See Example 2.- Parameters
-
Parameter Description method Specifies the HTTP method to use, such as "GET", "POST", "PUT", "DELETE" and so on. url Specifies the URL to send the request to. async Supplies a Boolean value indicating whether or not to perform the operation asynchronously. username Required for NTLM authentication. This parameter specifies the name of the user. password Required for NTLM authentication. This parameter specifies the password of the user. domain Required for NTLM authentication. This parameter specifies the name of the domain. workstation Optional for NTLM authentication. This parameter specifies the name of the workstation.
Using HTTPS
If you want to use the HTTPS protocol to send the HTTP requests, you must first configure your Java virtual machine to handle the SSL certificates properly. If you do not want to do the configuration, use the RSBIHttpRequest.ignoreCertificates() method. In this case, your JVM is set to ignore the SSL certificates and the connection that is established is not secure.
Examples
Example 1
var request = new RSBIHttpRequest();
request.open('GET','http://example.com', false);
Example 2
var req = new RSBIHttpRequest();
req.open("GET", 'http://example.com', false, "username",
"password", "domain", "workstation");
orreq.open("GET", 'http://example.com', false, "username", "password", "domain");
Methods
getAllResponseHeaders()
- The
getAllResponseHeaders()
method returns a string with a list of header field definitions, which are separated by "\r\n".
getResponseHeader()
- The
getResponseHeader()
method returns a header field definition with the specified name.Parameter Description name Specifies the name of the HTTP header field definition that you want to get.
open()
-
Parameter Description method Specifies the HTTP method to use, such as "GET", "POST", "PUT", "DELETE" and so on. url Specifies the URL to send the request to. async Supplies a Boolean value indicating whether or not to perform the operation asynchronously. username Required for NTLM authentication. This parameter specifies the name of the user. password Required for NTLM authentication. This parameter specifies the password of the user. domain Required for NTLM authentication. This parameter specifies the name of the domain. workstation Optional for NTLM authentication. This parameter specifies the name of the workstation. Note: You can specify additional parameters in theopen()
method of RSBIHttpRequest class to use NTLM authentication. See Example 2.- Examples
var request = new RSBIHttpRequest(); request.open('GET','http://example.com', false);
var req = new RSBIHttpRequest(); req.open("GET", 'http://example.com', false, "username", "password", "domain", "workstation");
req.open("GET", 'http://example.com', false, "username", "password", "domain");
send()
- The
send()
method sends a JavaScript object to the web service.Parameter Description data Specifies the object that you want to sent in the HTTP request. setRequestHeader()
- The
setRequestHeader()
method allows setting the name and value of a header field definition.Parameter Description name Specifies the name of the HTTP header field definition that you want to send. value Specifies the value of the HTTP header field definition that you want to send. - Example
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
RSBIHttpRequest constants
Use the following states instead of constants to specify the state of the RSBIHttpRequest object.Constant | RSBIHttpRequest Object State |
---|---|
0 | Unitialized |
1 | Loading |
2 | Loaded |
3 | Interactive |
4 | Complete |
- Example
- See the example of retrieving the required data from the Internet.
if(request.readyState === request.Complete)
is used instead ofif(request.readyState === 4)
.function getStockData(url) { var request = new RSBIHttpRequest(); request.open('GET',url, false); var response = ''; request.onreadystatechange = function() { if(request.readyState === request.Complete) { response = request.responseText; } } request.send(null); return response; }