Client Class HttpClient

The wwHttp class provides a thin wrapper around the browser XmlHttp object to allow making callbacks. The control manages hooking up a callback handler and managing errors by calling the callback handler or error handler when the calls complete.

Focus of this control is to make the callback process very easy but still provide robust error management.

function HttpSample()
{
	var Http = new HttpClient();     
	var Result = Http.send("http://localhost/",null,
	                       function(result) { 
	                        alert("It worked: " + result);  // shows HTML result
	                       },
	                       function(error)
	                       {
	                        alert("Error: " + error.message);
	                       }
	                      };
}

Note that calls are asynchronous so results are fired into the result functions out of band. To make multiple simultaneous callbacks create multiple instances of this class.

Remarks

This class has no dependencies on server side features.

Class Members

MemberDescription

appendHeader

Appends an HTTP header to the current request.

o.wwHttp.addHeader(HeaderName,Value)

send

Used to make an asynchronous HTTP call to the server and return the result into a callback function. This method provides error handling and any errors that occur are fired into the OnError handler.

o.send(Url,PostData,Callback,ErrorCallback)

accepts

The accept type(s) that are accepted for the response.

completed

Optional handler called when the call completes. Receives a string parameter that is the result of the HTTP request.

contentType

The content type for any POST data that might be sent.

errorHandler

Optional handler called when an error occurs. Receives an instance of CallbackException error object.

evalResult

Determines whether the result from the callback is automatically evaluated using eval(). Useful for JSON responses.

isMsAjaxJson

Flag that determines whether the called service is an ASP.NET ASMX or WCF service that returns 'wrapped objects'. If set HttpClient will unwrap the object and return only the actual result value.

method

The HTTP verb used on this request.

serverUrl

The Url that is to be accessed on the server. This parameter can also be passed and is overridden by the first parameter to send but setting the property can provide a default and reusable value.

timeout

Determines the timeout for this request before it is considered failed.

See also:

Class HttpClient

© West Wind Technologies, 1996-2016 • Updated: 12/18/15
Comment or report problem with topic