Total Pageviews

Monday, May 26, 2014

Event networkRequest

Event NetWorkRequest
សំរាប់ networkRequest វាមាន Properties ដូចខាងក្រោមះ
Properties
event.isError
បើសិនជា network error កើតឡើងសំរាប់ Property is true បើមិនទេវានឹង false។ នៅក្នុងករណី ៤០៤​error ដែលមិនមែនជា error in request ប៉ុន្តែវាជា incorrect/inexisting URL សំរាប់តំលៃ Property នឹងត្រូវ false
សូមមើលកូដះ
local function networkListener( event )
        if ( event.isError ) then
                print( "Network error!")
        else
                print ( "RESPONSE: " .. event.response )
        end
end
postData = "color=red&size=small"
local params = {}
params.body = postData

network.request( "http://127.0.0.1/formhandler.php", "POST", networkListener, params)

event.name
វាតែងតែ networkRequest សំរាប់ network request events

event.phase
សំរាប់ phase of network request អាចជាតំលៃមួយដូចនេះ
Began the initial notification
Progress an intermediate progress notification with an updated value for bytes transferred
Ended the final notification when the request is finished

ចំណាំះ
សំរាប់
began phase event
សំរាប់ការ upload progress this notification នឹងទទួលមុនពេលដែល connecting to the remote and starting the request វានឹងផ្ទុកនៅ estimated upload size (bytesEstimated) បើសិនជាដឹង
សំរាប់ download progress this notification នឹងទទួលបន្ទាប់ពី posting the request and response headers វានឹងផ្ទុកនៅ response code headers and estimated size បើសិនជាដឹង

event.requestId
វាជា​ reference ក្នុងការ​ request ដែល corresponds ទៅកាន់ event។ សំរាប់តំលៃនេះគឺដូចគ្នានឹង return value ចេញពី call to network.request(), network.upload() or network.download()។ សំរាប់តំលៃនេះប្រើសំរាប់កំនត់ identify the specific request or cancel it តាមរយះ network.cancel()

event.status
សំរាប់ status code ត្រឡប់ចេញពី server ឧះ នៅពេលដែល request បាន success this will typically be 200
event.url
វាជា URL corresponding ទៅកាន់ request

event.responseHeaders
វាជាតារាងដែលផ្តល់នៅ response header value ជាមួយនឹង string keys
សូមមើលកូដះ
local function networkListener( event )
        print( "Content-Type of response is: " .. event.ResponseHeaders["Content-Type"] )
end
event.responseType
សំរាប់ encoding type របស់ response ដែលមានតាម status របស់វាះ
Text: the response content was determined to be text and was encoded as a UTF-8 string
Binary: the response content was determined to be binary was provided without any encoding
event.response
វាជា String ដែលឆ្លើយទៅនឹង response ចេញពី Server
event.bytesTransferred
សំរាប់តំលៃនេះបង្ហាញអំពីចំនួនលេខរបស់ bytes processed តាមការសំនូរពរ។
event.bytesEstimated
សំរាប់តំលៃរបស់វាបង្ហាញនៅចំនួន bytes ទៅតាមសំនូមពរ បើសិនជាមាន បើមិនទេវានឹង -1
ចំណាំះ សំរាប់តំលៃរបស់វាអាស្រ័យលើប្រភេទរបស់ Progress ដែលបង្ហាញការសំនូរពរ។ បើសិនជា upload progress is specified ពេលនោះតំលៃរបស់វានឹង corresponds ទៅកា​ន់ការសំនូរពរនៃការ upload
បើសិនជា download progress specified វានឹងresponse ទៅកាន់ការឆ្លើយតប។


No comments:

Post a Comment