03-25-2013 04:22 AM
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!
Solved! Go to Solution.
03-25-2013 10:05 AM - edited 03-25-2013 10:05 AM
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 ?
03-26-2013 10:58 AM
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!
03-27-2013 11:46 AM
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.