LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

opening url and reading result

Hello,
I'm trying to do the following:

1)opening a web page: http://www.google.be/search?hl=nl&q=myquery&btnG=Google+zoeken&meta=
2)reading the results of this query
3)(not important) do some post processing on the results

I tyied to do this:
if(0==ConnectToTCPServerEx(&handle,80,"www.google.be", mytcpcallback,0,0,TCP_ANY_LOCAL_PORT))
{
if(0<=ClientTCPWrite(handle,"http://www.google.be/search?hl=nl&q=ff&btnG=Google+zoeken&meta="
,strlen("http://www.google.be/search?hl=nl&q=ff&btnG=Google+zoeken&meta=")
,5000))
...
}
int CVICALLBACK mytcpcallback (unsigned handle, int xType, int errCode, void *callbackData)
{
char * data[1536];
switch (xType) {
case TCP_DISCONNECT:
DebugPrintf(GetTCPErrorString(errCode));
DebugPrintf(GetTCPSystemErrorString());
break;
case TCP_DATAREADY:
ClientTCPRead(handle,data,1536,5000);
DebugPrintf("%s\n",data);
break;
}
return 0;
}


This doesn't seem to work. I can never read any data...
Any suggestion?
Thanks,
Kristrio
0 Kudos
Message 1 of 6
(4,378 Views)
I'm not getting any further for the moment and no one is helping me. Perhaps I need to tell you that the url used (www.google.com) is just an example. In fact I have to do this with an other internal url. So it is not a joke! I really need a solution.

In my real case I need the response from this :
http://wks88/cgi-bin/prod/macaddr.py?btypearg=ALL&stickernbrarg=07131103337

The last number of this url may change as it depends on a variable.

Hope you help me!

Kristrio
0 Kudos
Message 2 of 6
(4,342 Views)
aie aie aie.... you are not reading anything back because you are talking shit to google !

never heard of HTTP ? to perform any action on the internet (and get useful results), you need to conform to the appropriate protocol, and in your case the protocol is HTTP !
you can download a description of the protocol here:
(version 1.0, old but still mostly supported) http://www.rfc-editor.org/cgi-bin/rfcdoctype.pl?loc=RFC&letsgo=1945&type=http&file_format=txt
(version 1.1, newer but more complicated) http://www.rfc-editor.org/rfc/rfc2616.txt

you will soon find that supporting the whole protocol is quite complicated, so you would be better using an external library which will take care of the details of the protocol. one of them is CURL, also libhttp, urllib, etc... search the internet for "C HTTP library".

unfortunately, CVI has some functions for reading/writing POP3 telnet or FTP, but none for HTTP...

ps: you would get something better by sending: "GET http://www.google.be/search?hl=nl&q=myquery&btnG=Google+zoeken&meta= HTTP/1.1\nHost: www.google.be\n\n", but i did not tell you that, ok ? i shall not be held liable to any damage or disruption of service you may cause by using the above line as is... RTFM first !
0 Kudos
Message 3 of 6
(4,340 Views)
my answer would not be complete without mentioning that Windows already provides a set of function for accessing urls. they are located in the wininet library. look for InternetOpen, InternetOpenUrl and related functions...

you will find attached a code sample to open an url and download its content to a file.
in order to compile this code, you will need to:
- install the windows sdk that comes bundled with CVI (if it's not already installed)(or download it from microsoft website)
- add "wininet.lib" from the windows sdk folder (<cvi install dir>\sdk\lib\) to your project
input url and output filename are in defined in constant variables, experiment with them. also read the documentation for InternetOpenUrl and InternetOpen as they support a bunch of flags for configuring the connection to suit your need and network configuration.

Message 4 of 6
(4,333 Views)
Thanks for the input!
I managed to get the data I needed. I used the curl.exe program!
Kristrio

Message Edited by kristrio on 11-16-2007 04:41 AM
0 Kudos
Message 5 of 6
(4,313 Views)

Thanks!  Ancient thread, but this helped me immensely.  Struggling to learn Web access, and this example finally was the one that worked.  Thank you very much.

0 Kudos
Message 6 of 6
(2,017 Views)