[Long] Moving a REST request from Desktop to Server
Malte Brill
revolution at derbrill.de
Tue Mar 7 18:56:59 EST 2017
Hi all,
I am trying to move a request I do from a desktop app to a liveCode server script and am facing the problem that some of the stuff I use (most of it libURL stuff) is not available on the server. Now I wonder how I could translate it…
Scenario is the following:
Problem is libURLLastRHHeaders() is unavailable on server and can not easiely be copied from libURL
Anyone got an idea?
local sCookieHeader
on mouseUp
local tURL,tUser,tPassWord,tCookie,tSubmitId,tsubmit,tJson,tJsonArray
local test
try
set the httpHeaders to empty
put „aUser" into tUser
put „aPassword" into tPassWord
put "264812" into tSubmitID
put "Log+in" into tSubmit
get libURLFormData("userName", tUser,"password", tPassword,"submit",tSubmit,"submitID",tSubmitId) — not available on Server, but can be copied from libURL
post it to url "http://test.com/login.php"
_storeCookies libURLLastRHHeaders() — needed to authenticate. libURLLastRHHeaders unavailable
set the httpHeaders to sCookieHeader
put fld "URL" into tURL
put URL tURL into tJson
catch theErr
put theErr
end try
end mouseUp
## Parse header returned from a server and create a cookie header that
## can be sent back: Cookie: cookie1;cookie2;cookie3;...
private command _StoreCookies pHeader
local theCharNo,theCookieLine,theLineNo,theOffset
put empty into sCookieHeader
put 0 into theOffset
repeat forever
put lineoffset("Set-Cookie:", pHeader, theOffset) into theLineNo
if theLineNo > 0 then
add theOffset to theLineNo
put line theLineNo of pHeader into theCookieLine
delete word 1 of theCookieLine ## Set-Cookie:
put offset(";", theCookieLine) into theCharNo
if theCharNo > 0 then
delete char theCharNo to -1 of theCookieLine
end if
put theCookieLine & ";" after sCookieHeader
put theLineNo into theOffset
else
exit repeat
end if
end repeat
if the last char of sCookieHeader is ";" then
delete the last char of sCookieHeader
end if
if sCookieHeader is not empty then
put "Cookie: " before sCookieHeader
end if
return empty
end _StoreCookies
More information about the use-livecode
mailing list