I fixed a code as save ‘Set-Cookie’ of responseHeader in network.request eventlistener callback,and set it to ‘Cookie’ of header when execute the next network.request. As a result, a request succeeded.
The following is a code.
local Bluepay = { APIKEY\_BLUE = "7b6d669945bcfefad24a4d555c062c53d7f92a575cd159141b3d1cc046527bb4a3d3e00af326f06f3bfc20c044b4853337bc70855700361ca 4282dd64f3c137a", URLH\_INTERNAL = "http://bluepay-internal\_api.", URLENDPOINT = "twirllook.com", URLH\_CONFIG = "http://wallets-static.s3.amazonaws.com/config/", URL\_INTERNAL\_API = nil, completed\_0 = nil, completed\_n = nil, errorOccured = nil, setCookie = nil, } local function defaultEventListener(event) print(event.response) print(event.isError) print(event.status) local errorFlag = 0 if true == event.isError then errorFlag = 1 end local decoded = nil if nil == event.response then errorFlag = 1 else decoded = json.decode(event.response) if nil ~= event.responseHeaders then local resCookie = event.responseHeaders['Set-Cookie'] print("response.coockie:"..resCookie) Bluepay.setCookie = resCookie end end event.decoded = decoded if nil == decoded then errorFlag = 1 else if false == decoded.result then errorFlag = 1 end end local completed\_0 = Bluepay.completed\_0 local completed\_n = Bluepay.completed\_n local errorOccured = Bluepay.errorOccured Bluepay.completed\_0 = nil Bluepay.completed\_n = nil Bluepay.errorOccured = nil if 0 == errorFlag then if 0 == decoded.code then if nil ~= completed\_0 then completed\_0(event) end else if nil ~= completed\_n then completed\_n(event) end end else if nil ~= errorOccured then errorOccured(event) end end end function Bluepay:getInfo(uuid, deviceToken, deviceType, completed\_0, completed\_n, erroccured) if nil ~= Bluepay.completed\_0 or nil ~= Bluepay.completed\_n then print("called Bluepay:function already.") return end Bluepay.completed\_0 = completed\_0 Bluepay.completed\_n = completed\_n Bluepay.errorOccured = erroccured local api = "/v1/users/info" local uri = (nil ~= Bluepay.URL\_INTERNAL\_API and Bluepay.URL\_INTERNAL\_API or (Bluepay.URLH\_INTERNAL..Bluepay.URLENDPOINT))..api local params = {headers={}} params.body = nil params.headers["Blue-Device-Type"] = deviceType params.headers["Blue-Device-Token"] = deviceToken params.headers["Blue-API-Key"] = Bluepay.APIKEY\_BLUE params.headers["Blue-Device-UUID"] = uuid params.headers["Cookie"] = Bluepay.setCookie print("getInfo") print("uri:"..uri) print("params:"..dumpdata:dump(params)) print("params.headers:"..dumpdata:dump(params.headers)) network.request(uri, "GET", defaultEventListener, params) end
The following is a log.
01-05 15:18:18.159 I/Corona ( 9407):
response.coockie:laravel_session=eyJpdiI6ImMxajRCR3F2b01lUytyb3Rjc0VwSEE9PSIsInZhbHVlIjoiZ2FDejBEZFl2YUVYOEtQTmFJM
UV4b2hqcjk2d00xY2FrSk9tekdCRDZYNmR2VGlnbUZPeXhpWmtvQTVZciszcDMrcTVySXAxZDFIT1J1cXpvNUJsUWc9PSIsIm1hYyI6ImQ4OTg1ZTB
lMWM3MzkxY2JlNmY5NTZkMWVlN2NiNGQ4MDFlNjZkMzUzMmE3NDcwMzgxODJiNjEyYzI2ZGY2MTYifQ%3D%3D; expires=Mon, 05-Jan-2015
09:19:22 GMT; Max-Age=7200; path=/; domain=internal.twirllook.com; httponly
01-05 15:18:18.159 I/Corona ( 9407): getInfo
01-05 15:18:18.160 I/Corona ( 9407): uri:http://internal.twirllook.com/v1/users/info
01-05 15:18:18.160 I/Corona ( 9407): params:{headers = table: 0x1fb79a8, }
01-05 15:18:18.160 I/Corona ( 9407): params.headers:{Blue-API-Key =
"7b6d669945bcfefad24a4d555c062c53d7f92a575cd159141b3d1cc046527bb4a3d3e00af326f06f3bfc20c044b4853337bc70855700361ca
4282dd64f3c137a", Blue-Device-Type = “android”, Blue-Device-UUID = “928FCB6A-95ED-4867-B666-E299C40EFE31”, Cookie
=
"laravel_session=eyJpdiI6ImMxajRCR3F2b01lUytyb3Rjc0VwSEE9PSIsInZhbHVlIjoiZ2FDejBEZFl2YUVYOEtQTmFJMUV4b2hqcjk2d00xY
2FrSk9tekdCRDZYNmR2VGlnbUZPeXhpWmtvQTVZciszcDMrcTVySXAxZDFIT1J1cXpvNUJsUWc9PSIsIm1hYyI6ImQ4OTg1ZTBlMWM3MzkxY2JlNmY
5NTZkMWVlN2NiNGQ4MDFlNjZkMzUzMmE3NDcwMzgxODJiNjEyYzI2ZGY2MTYifQ%3D%3D; expires=Mon, 05-Jan-2015 09:19:22 GMT;
Max-Age=7200; path=/; domain=internal.twirllook.com; httponly", Blue-Device-Token =
"APA91bGSGVFCJG0MLAW19JPQgVyUqDvQxfPC60bnLxHGK6xFSybebhDJlMCA4USkyOgxpHr6_dWQwUiXSttbechHda3ZvUdvk1Dp1UtFpAAE1S98t
YYetu_wB3JPuB7O8NrmbHxZmqp16V8gsq9EjiVWfGiQMtsQaQ", }
01-05 15:18:18.163 D/dalvikvm( 9407): threadid=16: interp stack at 0x5c973000
01-05 15:18:18.163 D/dalvikvm( 9407): threadid=16: calling run()
01-05 15:18:18.164 I/System.out( 9407): [socket][37] connection
internal.twirllook.com/103.4.12.118:80;LocalPort=44453(30000)
01-05 15:18:18.164 I/System.out( 9407): [CDS]connect[internal.twirllook.com/103.4.12.118:80] tm:30
01-05 15:18:18.165 E/Posix ( 9407): [CDS]Libcore_io_Posix-throwErrnoException, functionName: connect; errno:
Operation now in progress
01-05 15:18:18.166 D/Posix ( 9407): [Posix_connect Debug]Process jp.co.bluepay.wallets :80
01-05 15:18:18.192 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.193 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.256 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.257 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.270 V/ActivityManager( 238): getTasks: max=3, flags=0, receiver=null
01-05 15:18:18.270 V/ActivityManager( 238): jp.co.bluepay.wallets/com.ansca.corona.CoronaActivity:
task=TaskRecord{4182b8f0 #36 A jp.co.bluepay.wallets}
01-05 15:18:18.270 V/ActivityManager( 238): com.anddoes.launcher/.Launcher: task=TaskRecord{4163b7c0 #2 A
com.anddoes.launcher}
01-05 15:18:18.271 V/ActivityManager( 238): com.android.settings/.SubSettings: task=TaskRecord{41952e40 #7 A
com.android.settings}
01-05 15:18:18.271 V/ActivityManager( 238): com.android.settings/.SubSettings: task=TaskRecord{41952e40 #7 A
com.android.settings}
01-05 15:18:18.271 V/ActivityManager( 238): com.android.settings/.Settings: task=TaskRecord{41952e40 #7 A
com.android.settings}
01-05 15:18:18.271 V/ActivityManager( 238): We have pending thumbnails: null
01-05 15:18:18.272 V/ActivityManager( 238): getTasks: max=3, flags=0, receiver=null
01-05 15:18:18.272 V/ActivityManager( 238): jp.co.bluepay.wallets/com.ansca.corona.CoronaActivity:
task=TaskRecord{4182b8f0 #36 A jp.co.bluepay.wallets}
01-05 15:18:18.272 V/ActivityManager( 238): com.anddoes.launcher/.Launcher: task=TaskRecord{4163b7c0 #2 A
com.anddoes.launcher}
01-05 15:18:18.272 V/ActivityManager( 238): com.android.settings/.SubSettings: task=TaskRecord{41952e40 #7 A
com.android.settings}
01-05 15:18:18.272 V/ActivityManager( 238): com.android.settings/.SubSettings: task=TaskRecord{41952e40 #7 A
com.android.settings}
01-05 15:18:18.272 V/ActivityManager( 238): com.android.settings/.Settings: task=TaskRecord{41952e40 #7 A
com.android.settings}
01-05 15:18:18.272 V/ActivityManager( 238): We have pending thumbnails: null
01-05 15:18:18.320 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.321 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.384 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.385 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.450 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.450 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.514 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.514 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.523 I/SurfaceFlinger( 100): [SurfaceFlinger] frames:17, duration:1.029000, fps:16.518656
01-05 15:18:18.579 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.579 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.613 I/System.out( 9407): [socket][/192.168.17.23:44453]
01-05 15:18:18.613 I/System.out( 9407): rx timeout:30000
01-05 15:18:18.645 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.645 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.709 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.709 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.774 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.776 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.838 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.839 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.845 D/StateMachine( 238): handleMessage: E msg.what=131155
01-05 15:18:18.845 D/StateMachine( 238): processMsg: ConnectedState
01-05 15:18:18.845 D/WifiStateMachine( 238): ConnectedState{ what=131155 when=-1ms arg1=22 }
01-05 15:18:18.845 D/WifiCommon( 238): [wlan0] Issue cmd = ‘SIGNAL_POLL’
01-05 15:18:18.846 D/wpa_supplicant( 450): CMD = SIGNAL_POLL
01-05 15:18:18.846 D/wpa_supplicant( 450): wpa_driver_signal_poll
01-05 15:18:18.847 I/WifiStateMachine( 238): fetchRssiAndLinkSpeedNative, newRssi=-54
01-05 15:18:18.847 D/StateMachine( 238): handleMessage: X
01-05 15:18:18.903 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.903 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.967 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:18.967 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:19.031 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:19.031 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:19.095 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:19.096 I/SurfaceView( 9407): Changes: creating=false format=false size=false visible=false left=false
top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceVisibilityChanged=false
forceSizeChanged=false mVisible=true mRequestedVisible=true
01-05 15:18:19.144 I/System.out( 9407): [CDS]close[44453]
01-05 15:18:19.145 I/System.out( 9407): close [socket][/0.0.0.0:44453]
01-05 15:18:19.146 D/dalvikvm( 9407): threadid=16: exiting
01-05 15:18:19.146 D/dalvikvm( 9407): threadid=16: bye!
01-05 15:18:19.146 D/dalvikvm( 9407): threadid=0: freeing
01-05 15:18:19.158 I/Corona ( 9407): {“result”:true,“code”:0,“errmsg”:"",“errtitle”:"",“info”:
{“FirstName”:“r”,“LastName”:“n”,“Tel”:“03-5843-1151”,“Birth”:“1969-03-29”,“Sex”:1}}
01-05 15:18:19.158 I/Corona ( 9407): false
01-05 15:18:19.158 I/Corona ( 9407): 200
Why isn’t cookie set automatically in android?
Do I have to manage cookie manually in the application?
This problem seems related to this topic.
http://forums.coronalabs.com/topic/53519-lost-session-on-android-how-to-manage-cookies/
But it isn’t a good way.
How should I do for cookie to be managed automatically like ios?