Quark
#
Modules #
quark/action
quark/app
quark/bubbles
quark/buffer
quark/checkbox
quark/css
quark/ctr
quark/dialog
quark/event
quark/font
quark/fs
quark/http
quark/index
quark/keyboard
quark/media
quark/nav
quark/os
quark/path
quark/pkg
quark/screen
quark/stepper
quark/storage
quark/test
quark/types
quark/util
quark/view
quark/window
quark/_common
quark/_event
quark/_ext
quark/_util
Quark v1.2.0 Documentation
Table of Contents
-
quark/http
- Enum: HttpMethod
- Enum: HttpReadyState
- StreamResponseCallback
- HttpEvent
-
Class: NativeHttpClientRequest
- NativeHttpClientRequest
- nativehttpclientrequest.uploadTotal
- nativehttpclientrequest.uploadSize
- nativehttpclientrequest.downloadTotal
- nativehttpclientrequest.downloadSize
- nativehttpclientrequest.readyState
- nativehttpclientrequest.statusCode
- nativehttpclientrequest.url
- nativehttpclientrequest.httpResponseVersion
- nativehttpclientrequest.setMethod(method)
- nativehttpclientrequest.setUrl(url)
- nativehttpclientrequest.setSavePath(path)
- nativehttpclientrequest.setUsername(user)
- nativehttpclientrequest.setPassword(pwd)
- nativehttpclientrequest.disableCache(disable)
- nativehttpclientrequest.disableCookie(disable)
- nativehttpclientrequest.disableSendCookie(disable)
- nativehttpclientrequest.disableSslVerify(disable)
- nativehttpclientrequest.setKeepAlive(keepAlive)
- nativehttpclientrequest.setTimeout(timeoutMs)
- nativehttpclientrequest.setRequestHeader(name,value)
- nativehttpclientrequest.setForm(formName,value)
- nativehttpclientrequest.setUploadFile(formName,localPath)
- nativehttpclientrequest.clearRequestHeader()
- nativehttpclientrequest.clearFormData()
- nativehttpclientrequest.getResponseHeader(headerName)
- nativehttpclientrequest.getAllResponseHeaders()
- nativehttpclientrequest.send(data?)
- nativehttpclientrequest.pause()
- nativehttpclientrequest.resume()
- nativehttpclientrequest.abort()
- Class: HttpClientRequest
- Interface: RequestOptions
- Interface: ResponseData
- request(options)
- requestStream(options,cb)
- requestSync(options)
- download(url,save)
- upload(url,localFilePath)
- get(url)
- getStream(url,cb)
- post(url,data)
- getSync(url)
- postSync(url,data)
- downloadSync(url,save)
- uploadSync(url,localPath)
- abort(id)
- userAgent()
- setUserAgent(ua)
- cachePath()
- setCachePath(path)
- maxConnectPoolSize()
- setMaxConnectPoolSize(size)
- clearCache()
- clearCookie()
quark/http #
Enum: HttpMethod #
HttpMethod #
GET
GET wayPOST
POST wayHEAD
HEAD wayDELETE
DELETE wayPUT
PUT way
Enum: HttpReadyState #
HttpReadyState #
Initial
InitialReady
ReadySending
SendingResponse
ResponseCompleted
Completed
StreamResponseCallback #
@callback
StreamResponseCallback(stream)
@param
stream
:StreamResponse
HttpEvent #
@type
HttpEvent
=Event
<HttpClientRequest
,T
>@template
<T
>
Class: NativeHttpClientRequest #
NativeHttpClientRequest #
@extends
Notification
@private
nativehttpclientrequest.uploadTotal #
Total amount of data to be uploaded to the server
@get
uploadTotal
:number
nativehttpclientrequest.uploadSize #
The data size has been written and uploaded to the server
@get
uploadSize
:number
nativehttpclientrequest.downloadTotal #
Total amount of data to be downloaded
@get
downloadTotal
:number
nativehttpclientrequest.downloadSize #
Downloaded data volume
@get
downloadSize
:number
nativehttpclientrequest.readyState #
Request ready state
@get
readyState
:HttpReadyState
nativehttpclientrequest.statusCode #
Response status code
@get
statusCode
:number
nativehttpclientrequest.url #
Request target url
@get
url
:string
nativehttpclientrequest.httpResponseVersion #
Response http version
@get
httpResponseVersion
:string
nativehttpclientrequest.setMethod(method) #
Setting method way at request
@param
method
:HttpMethod
@return
void
nativehttpclientrequest.setUrl(url) #
Setting request url
nativehttpclientrequest.setSavePath(path) #
Setting local save path for downloading
nativehttpclientrequest.setUsername(user) #
Setting login username
nativehttpclientrequest.setPassword(pwd) #
Setting login password
nativehttpclientrequest.disableCache(disable) #
Disable or enable the cache
nativehttpclientrequest.disableCookie(disable) #
Disable or enable the cookie
nativehttpclientrequest.disableSendCookie(disable) #
Disable or enable the sending of cookie
nativehttpclientrequest.disableSslVerify(disable) #
Disable or enable the SSL verify
nativehttpclientrequest.setKeepAlive(keepAlive) #
Setting whether to keep active
nativehttpclientrequest.setTimeout(timeoutMs) #
Setting request timeout time
nativehttpclientrequest.setRequestHeader(name,value) #
Setting request header k/v
nativehttpclientrequest.setForm(formName,value) #
Setting the request form
nativehttpclientrequest.setUploadFile(formName,localPath) #
Setting the upload file path
nativehttpclientrequest.clearRequestHeader() #
Clear request all of headers
@return
void
nativehttpclientrequest.clearFormData() #
Clear request all of form data
@return
void
nativehttpclientrequest.getResponseHeader(headerName) #
Getting response header by the name
nativehttpclientrequest.getAllResponseHeaders() #
Getting all of response headers
@return
Dict
<string
>
nativehttpclientrequest.send(data?) #
Start send the request
@param
data?
:string
|Uint8Array
@return
void
nativehttpclientrequest.pause() #
Pause accepat the response data
@return
void
nativehttpclientrequest.resume() #
Resume accepat the response data
@return
void
nativehttpclientrequest.abort() #
Abort current request and response
@return
void
Class: HttpClientRequest #
HttpClientRequest #
@extends
NativeHttpClientRequest
For example:
import path from 'quark/path'
import * as fs from 'quark/fs'
var cl = new HttpClientRequest()
cl.setUrl('[`https://www.baidu.com/')`](https://www.baidu.com/'))
cl.setSavePath(path.documents('baidu.html'));
cl.onError.on(function(ev) { console.log(ev.data) })
// Prints:
// <Buffer 3c 68 74 6d 6c 3e 0d ... >
// <Buffer 3c 21 44 4f 43 54 59 ... >
// ...
cl.onData.on(function(ev) {
console.log(ev.data);
})
cl.onEnd.on(function() {
// Prints:
// true
// 4 200
console.log(fs.existsSync(path.documents('baidu.html')))
console.log(cl.readyState, cl.statusCode)
})
cl.onReadystateChange.on(function() { console.log(cl.readyState, cl.statusCode) })
cl.send();
var cl2 = new HttpClientRequest()
cl2.setUrl('[`http://192.168.1.100:1026/Tools/uploadFile')`](http://192.168.1.100:1026/Tools/uploadFile'))
cl2.setMethod(HttpMethod.POST);
cl2.setUploadFile('uploadFile', path.resources('util/http.js'))
cl2.onEnd.on(function() {
// Prints: complete
console.log('complete')
})
cl2.send();
Interface: RequestOptions #
RequestOptions #
requestoptions.url? #
The target path url to request
url?
:string
requestoptions.method? #
The method way to request
method?
:HttpMethod
requestoptions.headers? #
setting custom request headers
headers?
:Dict
<string
>
requestoptions.postData? #
Non post requests ignore this option
postData?
:string
|Uint8Array
requestoptions.save? #
save body content to local disk
save?
:string
requestoptions.upload? #
upload loacl file
upload?
:string
requestoptions.timeout? #
request timeout time, default no timeout "0"
timeout?
:number
requestoptions.disableSslVerify? #
Is disable ssl verify
disableSslVerify?
:boolean
requestoptions.disableCache? #
Is disable cache
disableCache?
:boolean
requestoptions.disableCookie? #
Is disable cookie
disableCookie?
:boolean
Interface: ResponseData #
ResponseData #
responsedata.data #
response data
data
:Uint8Array
responsedata.httpVersion #
http version
httpVersion
:string
responsedata.statusCode #
status code
statusCode
:number
responsedata.responseHeaders #
response headers
responseHeaders
:Dict
<string
>
request(options) #
Sending HTTP request by the options
For example:
import path from 'quark/path'
// uploat file and save body data
var opts = {
url: '[`http://192.168.1.100:1026/Tools/uploadFile',`](http://192.168.1.100:1026/Tools/uploadFile',)
method: HttpMethod.POST,
headers: { test: 'test' },
// postData: 'a=A',
save: path.documents('uploadFile.html'),
upload: path.resources('util/http.js'),
disableSslVerify: false,
disableCache: true,
disableCookie: false,
};
request(opts).then(function(buff) {
// Prints: <Buffer ...>
console.log(buff)
}).catch(e=>{
// Fail
})
@param
options
:RequestOptions
@return
AsyncTask
<ResponseData
>
requestStream(options,cb) #
Sending HTTP request with stream way by the options
For example:
requestStream({
url: '[`http://192.168.1.100:1026/'`](http://192.168.1.100:1026/')
}, (d)=>{
// Prints: <Buffer ...>
console.log(d.data)
}).then(function() {
console.log('Ok')
}).catch(err=>{
//Fail
});
@param
options
:RequestOptions
@param
cb
:StreamResponseCallback
@return
AsyncTask
<void
>
requestSync(options) #
Sending HTTP sync request by the options
For example:
// Prints: <Buffer ...>
try {
console.log(http.requestSync({ url: '[`http://192.168.1.100:1026/'`](http://192.168.1.100:1026/') }));
} catch(e) {
//Fail
}
@param
options
:RequestOptions
@return
Uint8Array
download(url,save) #
Sending HTTP request with get way and save response data
@param
url
:string
request target url@param
save
:string
local save path@return
AsyncTask
<ResponseData
>
upload(url,localFilePath) #
Uploading local file data with post way
@param
url
:string
request target url@param
localFilePath
:string
local file path@return
AsyncTask
<ResponseData
>
get(url) #
Requesting HTTP data in GET way
@param
url
:string
@return
AsyncTask
<ResponseData
>
getStream(url,cb) #
Requesting HTTP data in GET way and and using the stream way receiving data
@param
url
:string
@param
cb
:StreamResponseCallback
@return
AsyncTask
<void
>
post(url,data) #
Sending data to server in POST way
@param
url
:string
@param
data
:string
|Uint8Array
@return
AsyncTask
<ResponseData
>
getSync(url) #
Syncing request HTTP data in GET way
@param
url
:string
@return
Uint8Array
postSync(url,data) #
Syncing send data to server by POST
@param
url
:string
@param
data
:string
|Uint8Array
@return
Uint8Array
downloadSync(url,save) #
Syncing download data from the url path and save to local path
@param
url
:string
@param
save
:string
@return
Uint8Array
uploadSync(url,localPath) #
Syncing upload data to server in the POST way
@param
url
:string
target server url@param
localPath
:string
local file path@return
Uint8Array
abort(id) #
abort async task by id
userAgent() #
Getting default http user-agent header
@return
string
setUserAgent(ua) #
Setting default http user-agent header
cachePath() #
Getting HTTP cache saving path
@return
string
setCachePath(path) #
Setting local HTTP cache saving path
maxConnectPoolSize() #
Getting network connection pool size
@return
Uint
setMaxConnectPoolSize(size) #
Setting network connection pool size
clearCache() #
To clear all of caches
@return
void
clearCookie() #
To clear all of cookies
@return
void