LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how execute a php script on external server

Solved!
Go to solution

Hi!

 

Here's my problem: I want to execute a php script on a server by calling a simple url. Here an example of a possible url: http://servername/dir/scriptname.php?var1=a&var2=2.

The return value is a html code.

 

I use CVI 2012 AND 3.5!

0 Kudos
Message 1 of 4
(3,773 Views)

CVI doesn't have a http interface library (that I know of).  However, I've used the telnet library to send commands as if it is a web browser, by doing something like this:

 

Fmt(tlsend, "%s<%s%s%s%s%s%s", "GET ", "http://servername/dir/", "http://servername/dir/scriptname.php?var1=a&var2=2", " HTTP/1.1\nHost: ", "servername", "\r\n");

 

tlsession = InetTelnetOpen("servername", 80, 0);

 

InetTelnetWrite(tlsession, tlsend, "\r\n", -1, &tlbyteswritten, 2000);

 

InetTelnetRead (tlsession, tlread, 25000, &tlbytesread, 2000);

 

Scan(tlread, "%s>.....", ....);

 

The other option would possibly be to use InetLaunchDefaultWebBrowser () and pass along the URL of your script and use some ActiveX trickery to get the information back from Internet Explorer, but I'm not sure how well that would work, plus you'd run into problems if the end user installs another web browser.

 

Oh, and CVI 3.5 Smiley Surprised ?

 

0 Kudos
Message 2 of 4
(3,758 Views)
Solution
Accepted by topic author DRiegel

Hi!

 

Thanks a lot! That's the way I will do it!

 

But I have to call a different get command. Here is my way: Fmt(tlsend, "%s %s", "GET ", http://servername/dir/scriptname.php?var1=a&var2=2");

The next problem is the answer of the InetTelnetRead. It returns with -4 "system socket error". But the result of the php-script is in tlread.

So my problem is nearly solved!

0 Kudos
Message 3 of 4
(3,737 Views)

I'm not sure why that would be causing a socket error, but still apparently retrieving the data from the server.  I have not seen that before.  You could try InetTelnetReadUntil() and read data until some fixed token that indicates the end of the output from the php script, if that's possible.  

0 Kudos
Message 4 of 4
(3,723 Views)