LiveCode LessonsHow To - Step-By-Step Guides To Tasks In LiveCode TSNetHow to send a custom HTTP request using the tsNet external

How to send a custom HTTP request using the tsNet external


There are many types of HTTP requests that can be made dependent on the server that you are connecting to.

The tsNet external makes working with these types of requests easy due to the inclusion of the tsNetCustom* functions.

In this lesson, the example code shows how you can use the tsNet external to send a HTTP DELETE request to a server.

Lay out the Stack

Create a new stack then drag a button and a field onto it.

Set the name of this field to "Output".

Save this stack.

Create the Script

Edit the script of the button that you placed on the stack by right clicking on the button and selecting "edit script".

Add the following code.

on mouseUp
   -- can be used for testing different HTTP methods
   put "" into tUrl
   -- Send a HTTP DELETE request
   put tsNetCustomSync(tUrl, "DELETE", tRequestHeaders, tResponseHeaders, tResult, tBytes) into tData
   -- tResult will be 200 if the tsNetCustomSync call was successful
   -- If this is not the case, we will inform the user
   if tResult is not 200 then 
      answer "Error sending HTTP DELETE request" 
      put tData into field "Output"
   end if 
end mouseUp


Switch to Run mode and click the button.

More information

The example code above sends a HTTP DELETE method without passing any further data to the server.  While this command supports the sending of HTTP headers to the server through the tRequestHeaders variable, it does not support sending any data in the body of the HTTP request.

It is recommended that you take a look at the tsNetCustomUpload* functions in the LiveCode dictionary if you need to send data in the HTTP request body.


Add your comment

E-Mail me when someone replies to this comment