Http

Http

package haxe

Available on all platforms

This class can be used to handle Http requests consistently across platforms. There are two intended usages:

  • call haxe.Http.requestUrl(url) and receive the result as a String (not available on flash)
  • create a new haxe.Http(url), register your callbacks for onData, onError and onStatus, then call request().

Constructor

new (url:String)

Creates a new Http instance with url as parameter.

This does not do a request until request() is called.

If url is null, the field url must be set to a value before making the call to request(), or the result is unspecified.

(Php) Https (SSL) connections are allowed only if the OpenSSL extension is enabled.

Variables

async:Bool

Available on js

cnxTimeout:Float

Available on cpp, cs, hl, java, lua, macro, neko, php, python

noShutdown:Bool

Available on cpp, cs, hl, java, lua, macro, neko, php, python

read only responseData:Null<String>

responseHeaders:Map<String, String>

Available on cpp, cs, hl, java, lua, macro, neko, php, python

url:String

The url of this request. It is used only by the request() method and can be changed in order to send the same request to different target Urls.

withCredentials:Bool

Available on js

Methods

addHeader (header:String, value:String):Http

addParameter (param:String, value:String):Http

cancel ():Void

Available on flash, js

Cancels this Http request if request has been called and a response has not yet been received.

customRequest (post:Bool, api:Output, ?sock:Socket, ?method:String):Void

Available on cpp, cs, hl, java, lua, macro, neko, php, python

fileTransfer (argname:String, filename:String, file:Input, size:Int, mimeType:String = "application/octet-stream"):Void

Available on cpp, cs, hl, java, lua, macro, neko, php, python

inline fileTransfert (argname:String, filename:String, file:Input, size:Int, mimeType:String = "application/octet-stream"):Void

Available on cpp, cs, hl, java, lua, macro, neko, php, python

Note: Deprecated in 4.0

dynamic onData (data:String):Void

This method is called upon a successful request, with data containing the result String.

The intended usage is to bind it to a custom function:
httpInstance.onData = function(data) { // handle result }

dynamic onError (msg:String):Void

This method is called upon a request error, with msg containing the error description.

The intended usage is to bind it to a custom function:
httpInstance.onError = function(msg) { // handle error }

dynamic onStatus (status:Int):Void

This method is called upon a Http status change, with status being the new status.

The intended usage is to bind it to a custom function:
httpInstance.onStatus = function(status) { // handle status }

request (?post:Bool):Void

Sends this Http request to the Url specified by this.url.

If post is true, the request is sent as POST request, otherwise it is sent as GET request.

Depending on the outcome of the request, this method calls the onStatus(), onError() or onData() callback functions.

If this.url is null, the result is unspecified.

If this.url is an invalid or inaccessible Url, the onError() callback function is called.

[js] If this.async is false, the callback functions are called before this method returns.

setHeader (header:String, value:String):Http

Sets the header identified as header to value value.

If header or value are null, the result is unspecified.

This method provides a fluent interface.

setParameter (param:String, value:String):Http

Sets the parameter identified as param to value value.

If header or value are null, the result is unspecified.

This method provides a fluent interface.

setPostData (data:String):Http

Sets the post data of this Http request to data.

There can only be one post data per request. Subsequent calls overwrite the previously set value.

If data is null, the post data is considered to be absent.

This method provides a fluent interface.

Static variables

static PROXY:{port:Int, host:String, auth:{user:String, pass:String}} = null

Available on cpp, cs, hl, java, lua, macro, neko, php, python

Static methods

static requestUrl (url:String):String

Available on cpp, cs, hl, java, js, lua, macro, neko, php, python

Makes a synchronous request to url.

This creates a new Http instance and makes a GET request by calling its request(false) method.

If url is null, the result is unspecified.

© 2005–2016 Haxe Foundation
Licensed under a MIT license.
http://api.haxe.org/haxe/Http.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部