Page 1 of 1

How do I use the pPostData parameter in tsNetPost?

Posted: Tue Aug 20, 2019 2:08 am
by KimD
I'm trying to teach myself how to get LC Desktop to transmit data to LC Server

1) On LC Server I have this script -
<?lc
put empty into tData
repeat for each key tKey in $_SERVER
put tKey & " : " & $_SERVER[tkey] & return after tData
end repeat
put "===================" & return after tData
put "xcontent : " & $_GET["xcontent"] after tData
put tData
?>

2) On LC Desktop I have a button that runs this script (note that there is no pPostData parameter) -
put tsNetPost(("Conn" & random(1000)),"https://www.mysite.com/myscript.lc?xcon ... ntent-Type: text/plain",,"APIResponseFromDataReceipt") into tFatalErrorsFromAPI

When I activate this button - my APIResponseFromDataReceipt handler returns what I'm expecting, including:
$_Server["QUERY_STRING"] contains "xcontent=ABC"; and
$_GET["xcontent"] contains "ABC"

3) Then I change my LC Desktop script to utilise the pPostData parameter -
put tsNetPost(("Conn" & random(1000)),"https://www.mysite.com/myscript.lc","Content-Type: text/plain","xcontent=ABC","APIResponseFromDataReceipt") into tFatalErrorsFromAPI

When I activate this button - my APIResponseFromDataReceipt handler returns:
$_Server["QUERY_STRING"] contains empty; and
$_GET["xcontent"] contains empty

In the tsNetPost with a pPostData parameter, I've tried:
- having the "?" as a suffix to the pURL parameter
- having the "?" as a prefix to the pPostData parameter
- not having the "?" in either the pURL or pPostData parameter
- removing the "Content-Type: text/plain"
But none of these options made any difference. In all cases $_Server["QUERY_STRING"] and $_GET["xcontent"] returned empty.

What is the correct format for using tsNetPost > pPostData to transmit a "xcontent=ABC" query string to LC Server? Or am I misunderstanding things and "xcontent=ABC" is not "the data to be posted to the server" (as per the dictionary entry)?

Thanks in advance

Kim

Re: How do I use the pPostData parameter in tsNetPost?

Posted: Tue Aug 20, 2019 5:07 pm
by jacque
I don't know the answer since I always use the built-in POST but I'm wondering what you get if you try:

POST <data > to <url>

Re: How do I use the pPostData parameter in tsNetPost?

Posted: Wed Aug 21, 2019 3:58 am
by KimD
Thanks Jacque

I have it working with:
- Put URL; and
- Load URL; and
- tsNetPost, if I include the query string in the pURL (and not in the pPostData).

I want to use the tsNet library because it offers a bunch of other features that will be useful to me later.

I'm mostly just curious as to how it's supposed to work. I have it working using tsNetPost and appending the query string as a suffix to the pURL, but then, what's the pPostData parameter for? I'm entirely self-taught. I suspect that I'm not understanding what is meant by the dictionary entry for pPostData - "The data to be 'posted' to the server". I'm ASSUMING that the query string is the data to be posted to the server, but maybe it isn't.

Anyway - I'm off on holiday tomorrow (trekking in Nepal). I'll do some more experimenting when I get back.

Regards

Kim

Re: How do I use the pPostData parameter in tsNetPost?

Posted: Wed Aug 21, 2019 6:53 am
by FourthWorld
LC's post command automatically uses tsNet when it's available, and offers simpler syntax.

But for now, focus on Nepal. Enjoy. This message will still be here when you return.

Re: How do I use the pPostData parameter in tsNetPost?

Posted: Thu Oct 10, 2019 4:53 am
by KimD
Back from Nepal and at my desk. Oh joy ;-)

But I think that I have sorted out my problem. I hadn't understood the difference between POST and GET/PUT methods. Simple version:
- GET & PUT : pass data in the query string, populate the Query_String element of livecode servers $_Server array variable, and populate livecode servers $_Get array variable
- POST : passes data in the message body (and usually not the query string), does not populate the Query_String element of livecode servers $_Server array variable, and populates livecode servers $_Put array variable.

So, my tsNetPost script was working all along, and all that I needed to do was read $_Put["myvariablename"] on the server.

Thanks for your help.

Kim