How do I use the pPostData parameter in tsNetPost?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
KimD
Posts: 184
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

How do I use the pPostData parameter in tsNetPost?

Post by KimD » Tue Aug 20, 2019 2:08 am

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5084
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

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

Post by jacque » Tue Aug 20, 2019 5:07 pm

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>
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

KimD
Posts: 184
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

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

Post by KimD » Wed Aug 21, 2019 3:58 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6791
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Wed Aug 21, 2019 6:53 am

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”