Skip to Content
It is currently October 17th, 2019, 6:41 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: September 7th, 2018, 9:17 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 100
I'm a very newbie with PAL programming.

I was looking for the functions
Code:
WebToStr()
and
Code:
WebToFile()
to understand what they are supposed to do etc.

But I didn't find anything about.
What do they do
What they expect to have returned, once they've made a call?
etc ...

Can you please help me?

Thanks a million in advance


Top
 Profile  
Reply with quote  
PostPosted: September 8th, 2018, 5:49 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 100
no one knows please?


Top
 Profile  
Reply with quote  
PostPosted: September 10th, 2018, 12:20 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7878
Location: Aachen (Germany)
Quote:
WebToFile procedure



See also Example

Unit

FileUtils



Declaration

procedure WebToFile(Filename: String; URL: String);



Description

Grabs an HTTP webpage and saves the contents to file.



Filename must contain the full path to the file to which the contents will be saved.

URL to the webpage that needs to be grabbed.



This procedure is non-blocking and will thus not freeze the user interface while it is processing the page.


and:

Quote:
WebToStr function



See also Example

Unit

FileUtils



Declaration

function WebToStr(URL: String): String;



Description

Grabs the contents of a remote webpage (URL) and saves the data to a string.

This call is blocking meaning it will freeze SAM Broadcaster interface operation while the webpage is being downloaded. We recommend using the WebToFile procedure instead since it is non-blocking. Even better is the new THttpClient class that allows for more advanced Http requests.



URL is the direct link to the webpage.

The contents of the page will be returned.


Straight from the PAL Help.

To sum it up: WebToFile downloads a web resource and prints the text content to a File on your harddisk. WebToStr takes the text content of a web resource and returns that text as a string. The first one will just continue downloading in the background. WebToStr however is a blocking function and will freeze the UI of SAM and probably any future actions like switching to the next track etc while it downloads the web resource.

Neither is made for downloading large files, better use the THttpClient for those use cases.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: September 10th, 2018, 3:48 pm 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 100
First of all: thanks a lot for your reply.

i tired to experiment with this. But just calling a .php file I've made, from a website, what I see is that:
- The PHP file was never called (but the script was running)
- The script returned always that the site is moved permanently

Code:
...
...
callingStr := 'https://www.mydomain.com/sam.php'
    + '?msg=TestTest';
WebToFile('C:\sam-fromWeb\test.txt', callingStr);
...
...


Here the PHP code

Code:
$message = $_GET['msg'];
$my_file = 'file.txt';
$handle = fopen($my_file, 'a') or die('Cannot open file:  '.$my_file);
fwrite($handle, "\n".$message.$_SERVER['REMOTE_ADDR']);


The
Code:
file.txt
is empty after any supposed call.
While, if I call it via browser (same string as above), the PHP works fine.

I guess that the call by
Code:
WebToFile()
is calling and expecting something else ... but I have not clue what ... hence my question.


Top
 Profile  
Reply with quote  
PostPosted: September 11th, 2018, 12:33 pm 
Offline
SVS Member
SVS Member

Joined: December 6th, 2004, 9:00 am
Posts: 7878
Location: Aachen (Germany)
If you're on a SAM version older than 2018.1, you can't call https URLs. SAM will try to call the http version and your webserver will try to redirect it to HTTPS.
SAM pre-2018.2 can also not follow some redirects on top of that. That's most likely why you see the redirect page and not the one you're looking for.

_________________
Benedikt Bauer - SVS (Spacial Volunteer Support)

We're offering custom PAL / PHP code and general SAM assistance at palscripts.com

My Project:
Send "Now Playing" from SAM to Twitter and/or Facebook | Sourcecode


Top
 Profile  
Reply with quote  
PostPosted: September 12th, 2018, 8:00 am 
Offline
Senior User
Senior User

Joined: September 7th, 2018, 9:00 am
Posts: 100
Mastacheata wrote:
If you're on a SAM version older than 2018.1, you can't call https URLs. SAM will try to call the http version and your webserver will try to redirect it to HTTPS.
SAM pre-2018.2 can also not follow some redirects on top of that. That's most likely why you see the redirect page and not the one you're looking for.

Thanks a million.

To be able to work, I redirected the page with the script to HTTP and now it's working perfectly


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group