[Long] Moving a REST request from Desktop to Server
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 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: [Long] Moving a REST request from Desktop to Server
Malte Brill wrote: > 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… Have you considered running a standalone as your CGI? Standalones can be run facelessly with a -ui flag, and while they require a one-time cost to set up a library to read stdin and parse the request and env vars, once you're set up you get something LiveCode Server can't offer: complete compatibility with the LiveCode Script desktop syntax. LC Server is great for many things, but since it doesn't work like LC on the desktop I don't use it for anything beyond testing. I need to debug, and by not using the Server engine I can run my scripts right in the IDE. Last week I was going to put together some notes on this to make using LC standalones as CGIs easier, but as luck would have it I couldn't get either Server or a standalone running as a CGI on either of my shared hosting accounts, for reasons that appear to be related to the RAM requirements from font loading: http://quality.livecode.com/show_bug.cgi?id=14115 I have a workaround for that (thanks to some clever assist from Peter Brett and Mark Waddingham), but it's kinda funky and non-obvious to set up, so while it might work okay for me once in a while it's not the sort of thing I want to tell other people is reflective of how we do things in the LC world. We are, after all, about simplicity, or at least strive for it. But if you're on a VPS (about half our users are*) perhaps we can continue this discussion and explore simple means of using standalones as CGIs. It really is a much simpler overall workflow once you get it going. * I ran this survey on the LC forums - if you haven't voted please chime in on how you use LC on servers: POLL: LiveCode Server deployment http://forums.livecode.com/viewtopic.php?f=15&t=26772 -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: [Long] Moving a REST request from Desktop to Server
Hi Richard, no, I did not considder using a standalone as a CGI engine. I am in a rather difficult environment with the project (government servers that have ridiculous tests and approval times for changed solutions). On top of that, I would not want to lose the benefit of using liveCode PHP style. For most of what I do with LC server I am perfectly happy with the way it works. However, not having some stuff that libURL offers available (even though the dictionary states otherwise, in the case of libURLLastRHHeaders, Platforms desktop, server). Technically it should be possible if the Server script does a POST to a remote Server to see the RAW response in some form. In my case this would help a lot. I built quite a nice Framework (at least it works quite well for me) around the Server engine and it would be quite labor intense to change what I have. The only option I would see, would be moving the WEBSERVICE request into my LC Desktop client, which is what I’d rather avoid… :-( Cheers, Malte ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: [Long] Moving a REST request from Desktop to Server
A how-to for using standalones as CGI's is a fantastic idea! I've spent hours trawling through the mailing list archives for a definitive set of instructions on how to set this up but could never string together enough fragments of information to get it working. On Wed, Mar 8, 2017 at 12:28 AM, Richard Gaskin via use-livecode < use-livecode@lists.runrev.com> wrote: > Malte Brill wrote: > > > 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… > > Have you considered running a standalone as your CGI? > > Standalones can be run facelessly with a -ui flag, and while they require > a one-time cost to set up a library to read stdin and parse the request and > env vars, once you're set up you get something LiveCode Server can't > offer: complete compatibility with the LiveCode Script desktop syntax. > > LC Server is great for many things, but since it doesn't work like LC on > the desktop I don't use it for anything beyond testing. I need to debug, > and by not using the Server engine I can run my scripts right in the IDE. > > Last week I was going to put together some notes on this to make using LC > standalones as CGIs easier, but as luck would have it I couldn't get either > Server or a standalone running as a CGI on either of my shared hosting > accounts, for reasons that appear to be related to the RAM requirements > from font loading: > http://quality.livecode.com/show_bug.cgi?id=14115 > > I have a workaround for that (thanks to some clever assist from Peter > Brett and Mark Waddingham), but it's kinda funky and non-obvious to set up, > so while it might work okay for me once in a while it's not the sort of > thing I want to tell other people is reflective of how we do things in the > LC world. We are, after all, about simplicity, or at least strive for it. > > But if you're on a VPS (about half our users are*) perhaps we can continue > this discussion and explore simple means of using standalones as CGIs. It > really is a much simpler overall workflow once you get it going. > > > * I ran this survey on the LC forums - if you haven't voted please chime > in on how you use LC on servers: > > POLL: LiveCode Server deployment > http://forums.livecode.com/viewtopic.php?f=15&t=26772 > > -- > Richard Gaskin > Fourth World Systems > Software Design and Development for the Desktop, Mobile, and the Web > > ambassa...@fourthworld.comhttp://www.FourthWorld.com > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: [Long] Moving a REST request from Desktop to Server
Malte Brill wrote: > no, I did not considder using a standalone as a CGI engine. I am > in a rather difficult environment with the project (government > servers that have ridiculous tests and approval times for changed > solutions). On top of that, I would not want to lose the benefit > of using liveCode PHP style. The merge function is similar, but just different enough to prevent us from using it to test LC Server scripts in the LC IDE. :( If anyone else here would find that useful perhaps I could submit a request for that. I'm thinking maybe something like: put merge( tSomeStuff, "server") into tModifiedStuff ...where "server" is a flag that determines which merge style should be used. Or would it be simpler as a separate function, maybe something like: put serverMerge( tSomeStuff ) into tModifiedStuff Suggestions on that? It would be so nice if we could find some way to overcome the incompatibilities between LC Server and how LC normally handles scripts so we could debug as we write (the xTalk way!). -- Richard Gaskin Fourth World Systems Software Design and Development for the Desktop, Mobile, and the Web ambassa...@fourthworld.comhttp://www.FourthWorld.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: [Long] Moving a REST request from Desktop to Server
Hi, I would shell() to curl or a shell script and parse the result. om om On Tue, Mar 7, 2017 at 8:56 PM, Malte Brill via use-livecode < use-livecode@lists.runrev.com> wrote: > 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 > > > > ___ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode -- http://www.andregarzia.com -- All We Do Is Code. http://fon.nu -- minimalist url shortening service. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: [Long] Moving a REST request from Desktop to Server
+1 Andre - curl is definitely your friend for simple LC-server to other server communication. I maintain a server app that uses it to interact with the Vimeo server. https://curl.haxx.se/docs/ Phil Davis On 3/9/17 9:11 AM, Andre Garzia via use-livecode wrote: Hi, I would shell() to curl or a shell script and parse the result. om om On Tue, Mar 7, 2017 at 8:56 PM, Malte Brill via use-livecode < use-livecode@lists.runrev.com> wrote: 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 ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- Phil Davis ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode