tsNetGetSync tHeader

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Saman Sjr.
Posts: 49
Joined: Sat Nov 30, 2013 6:40 am

tsNetGetSync tHeader

Post by Saman Sjr. » Sun Nov 03, 2019 5:50 pm

Dear all,

the PHP code for call web service API :

<?php
$request = new Http_Request2('https://api.example.net/CustomerName=aabbcc');
$url = $request->getUrl();
$headers = array(
// Request headers
'clientID' => '1',
'clientName' => 'aaa',
'clientKey' => '111',
'client-Subscription-Key' => '12345678',
);
$request->setHeader($headers);
$parameters = array(
// Request parameters
);
$url->setQueryVariables($parameters);
$request->setMethod(HTTP_Request2::METHOD_GET);
// Request body
$request->setBody("{body}");
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>

How do I convert the code to LC using tsNetGetSync ?
I tried this but it always give no result :
put "clientID:'1', clientName:'aaa', clientKey:'111', client-Subscription-Key:'12345678'" into tHeaders
put tsNetGetSync("https://api.example.net/CustomerName=aabbcc", tHeaders, tRecvHeaders, tResult, tBytes) into tData

any example would be appreciated.

Thanks
SS

mimu
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 76
Joined: Tue Mar 05, 2013 7:00 pm
Location: Berlin
Contact:

Re: tsNetGetSync tHeader

Post by mimu » Mon Nov 04, 2019 9:16 pm

Hi Saman,
this should work:

Code: Select all

on mouseUp  
   local tRequestHeaders, tResponseHeaders, tResult, tBytes, tData
   local tSettings, tCharNo, tUrl
   
   put "https://api.example.net/CustomerName=aabbcc" into tUrl
   
   -- Build headers for HTTP request
   put "clientID:1" & cr into tRequestHeaders 
   put "clientName: aaa" & cr after tRequestHeaders 
   put "clientKey: 111" & cr after tRequestHeaders 
   put " client-Subscription-Key:12345678" after tRequestHeaders
   
   -- Disable connection re-use if required
   -- put true into tSettings["no_reuse"]
   put true into tSettings["save_sent_headers"]
   
   put tsNetGetSync(tUrl, tRequestHeaders, tResponseHeaders, tResult, tBytes, tSettings) into tData
   
   if the first word of tResult is not "tsneterr:" then
      -- For HTTP(s) requests, check response code to confirm success or failure
      if char 1 of tResult is not "2" then
         answer "HTTP response code" && tResult && "returned from server"
      end if
   else 
      answer "Error" && tResult && "returned from server"
   end if
   
   -- At this point:
   --  tResponseHeaders contains the headers returned from the server
   --  tRequestHeaders contains the headers that were sent to the server
   --  tData contains response body
   
end mouseUp
Ps: here you will find more code examples:
https://www.techstrategies.com.au/tsnet-resources/

Saman Sjr.
Posts: 49
Joined: Sat Nov 30, 2013 6:40 am

Re: tsNetGetSync tHeader

Post by Saman Sjr. » Tue Nov 05, 2019 2:45 am

Thanks mimu,
I got it working now.

Dankeschön

Post Reply

Return to “Internet”