Myna. HttpConnection

Connects to HTTP resources

Example

var h = new Myna.HttpConnection({
url:"http://www.google.com/search?q=myna+javascript",
method:"GET",
parameters:{
um:"1", //this looks in google groups instead of web search
},
})
try {
h.connect();

Myna.dump(h.getStatusCode(),"Status")
Myna.print(Myna.dump(h.responseHeaders,"headers"))
Myna.print(h.url)
Myna.print(h.getResponseText())
} catch(e){
Myna.print(Myna.formatError(e) + Myna.dump(h))
}
Summary
Myna. HttpConnectionConnects to HTTP resources
Functions and Properties
Myna. HttpConnectionConstructor function for HttpConnection class
responseHeadersobject containing the response headers.
connectconnects to HTTP resource specified in constructor
getResponseTextreturns http response body as text
getResponseXmlreturns http response body as an E4X XML object
getResponseDatareturns http response body as a byte array
getResponseStreamreturns http response body as a stream
getStatusCodereturns http response status code

Functions and Properties

Myna. HttpConnection

Myna.HttpConnection = function(options)

Constructor function for HttpConnection class

Parameters

optionsObject that describes the options for this connection.  See below.  Options:
urlURL to connect to.  The query string can be appended.  Example: http://www.google.com/search?q=myna+javascript
methodOptional default “GET” http method to use, one of GET,POST,PUT,DELETE
parametersOptional default null Object representing parameters to pass to the connection.  These are handled diffrently depending on method:
  • POST: these are the post parameters,
  • GET and PUT: these are the URL parametrers, unless that parameter is already specified in the URL.
  • DELETE: parameters are ignored
headersOptional default null Object representing headers to send with this request
contentOptional default null For POST and PUT types, this is the content to send in the body of the request.  Currently, this is expected to be a UTF-8 String.
contentTypeOptional default “text/plain” content type of posted content
usernameOptional default null username to send in a “Basic” auth header
passwordOptional default null password to send in a “Basic” auth header
timeoutOptional, default null If specified, this is the amount of time in milliseconds to wait for a connection, or between data chunks.  If null then timeouts are disabled.  If a timeout occurs then a java.net.SocketTimeoutException or org.apache.commons.httpclient.ConnectTimeoutException is thrown

Returns

Reference to HttpConnection instance

responseHeaders

object containing the response headers.

connect

Myna.HttpConnection.prototype.connect=function(timeout)

connects to HTTP resource specified in constructor

returns this connection object

getResponseText

Myna.HttpConnection.prototype.getResponseText=function()

returns http response body as text

getResponseXml

Myna.HttpConnection.prototype.getResponseXml=function()

returns http response body as an E4X XML object

See

getResponseData

Myna.HttpConnection.prototype.getResponseData=function()

returns http response body as a byte array

getResponseStream

Myna.HttpConnection.prototype.getResponseStream=function()

returns http response body as a stream

getStatusCode

Myna.HttpConnection.prototype.getStatusCode=function()

returns http response status code

Myna.HttpConnection = function(options)
Constructor function for HttpConnection class
Myna.HttpConnection.prototype.connect=function(timeout)
connects to HTTP resource specified in constructor
Myna.HttpConnection.prototype.getResponseText=function()
returns http response body as text
Myna.HttpConnection.prototype.getResponseXml=function()
returns http response body as an E4X XML object
Myna.HttpConnection.prototype.getResponseData=function()
returns http response body as a byte array
Myna.HttpConnection.prototype.getResponseStream=function()
returns http response body as a stream
Myna.HttpConnection.prototype.getStatusCode=function()
returns http response status code
Rhino’s E4X object