Discussion:
Using XMLHttpRequest
(too old to reply)
Roland Wingerter
2008-12-06 10:02:16 UTC
Permalink
Roland W. wrote >
Below is an enhanced version which saves the responseText to a file and
then displays it in an editor.
----------
*** Send request to google.com and save results to text file. ***
cStr1 = "http://www.google.com/search"
cStr2 = [hl=en&q=dbase&btnG=Google+Search]
objHttp = new OleAutoClient("Msxml2.XMLHTTP.4.0")
objHttp.open( "GET", cStr1 , false )
objHttp.Send(cStr2)

if objHttp.status == '200'
bSuccess = write2File(objHttp.responseText, "http_responseText.txt")

if bSuccess
* modi file "http_responseText.txt"
* The line above will throw an error:
* "contains line longer than 4096 characters"

// Open file using program associated with *.txt extension

openFile(set("Directory")+"\http_responseText.txt")
else
msgbox("Could not write repsonse text to file","Error")
endif

// inspect(objHttp)
endif

Function write2File( cString, cFileName )
local cString, bSuccess

bSuccess = false

try
oFile = new File()
oFile.create( cFileName, "W")
oFile.puts(cString)
oFile.close()
bSuccess = true
catch(exception e)
? e.code, e.message
endtry

return bSuccess

Function openFile( cFilePath )
set proc to :dUFLP:miscapi.prg addi
openURL(cFilePath)
return
Michael Nuwer
2008-12-06 14:05:32 UTC
Permalink
Hi Roland,

The following works.

cStr1 = "http://www.google.com/search"
// added "?"
cStr2 = [?hl=en&q=dbase&btnG=Google+Search]
objHttp = new OleAutoClient("Msxml2.XMLHTTP.4.0")
// added cStr1+cStr2
objHttp.open( "GET", cStr1+cStr2 , false )
// deleted "cStr2" as param of method.
objHttp.Send()


When you use HTTP GET method you must send all the data as part of the URL
address, i.e. on long string.

When you use HTTP POST method you must use the URL (only) in the open() method and
the name/value parameters in the send() method. (Google does not permit the POST
method.)
It tries to search google.com for "dbase".
Below is an enhanced version which saves the responseText to a file and
then displays it in an editor.
However, looking at the response in an editor it seems that we only get
the google home page, and not any search results.
From the following sentence in the Microsoft documentation it looks
This method takes one optional parameter, which is the requestBody to
use. The acceptable VARIANT input types are BSTR, SAFEARRAY of UI1
(unsigned bytes), IDispatch to an XML Document Object Model (DOM)
object, and IStream *.
<<
http://msdn.microsoft.com/en-us/library/ms763706(VS.85).aspx
Any ideas how to solve the problem?
Roland
Roland Wingerter
2008-12-07 10:26:54 UTC
Permalink
Post by Michael Nuwer
Hi Roland,
The following works.
cStr1 = "http://www.google.com/search"
// added "?"
cStr2 = [?hl=en&q=dbase&btnG=Google+Search]
objHttp = new OleAutoClient("Msxml2.XMLHTTP.4.0")
// added cStr1+cStr2
objHttp.open( "GET", cStr1+cStr2 , false )
// deleted "cStr2" as param of method.
objHttp.Send()
---------
Michael,

great, that solved it. I had tried cStr1+Str2, but missed the missing "?"
<g>.

Thank you very much for showing us this technique, it gives us new
possibilities to interact with web pages.

Roland
Roland Wingerter
2008-12-07 22:55:46 UTC
Permalink
I know you resolved the issue but, there is another approach you might
well be aware of but I thought I would post it just in case.
In the following URL a search will be done for greg and the location to
search will be dbase.com
The results show all my activity in the newsgroup.
http://www.google.com/search?source=ig&hl=en&rlz=&q=greg+site%3Adbase.com&aq=f
So you get the idea of replacing 'greg' with what you want to search for
and the dbase.com with the site to search.
---------
Thank you, Greg!

I knew the modifier "define:", but was not aware of "site:"

More Google search operators here:

http://www.google.com/help/operators.html

Roland
Greg Hill
2008-12-07 23:56:34 UTC
Permalink
Post by Roland Wingerter
I know you resolved the issue but, there is another approach you might
well be aware of but I thought I would post it just in case.
In the following URL a search will be done for greg and the location to
search will be dbase.com
The results show all my activity in the newsgroup.
http://www.google.com/search?source=ig&hl=en&rlz=&q=greg+site%3Adbase.com&aq=f
So you get the idea of replacing 'greg' with what you want to search for
and the dbase.com with the site to search.
---------
Thank you, Greg!
I knew the modifier "define:", but was not aware of "site:"
http://www.google.com/help/operators.html
The google guys are on the ball!

Your welcome,

That is a useful link.

I guess we all know about the + symbol that little guy can make searching
google a breeze. For example, If I changed the url above to include the
following:
greg+grid

Google would find all posting with greg but only if it also had the word
grid. That can be a huge help.
Take a step further to:
greg+"grid hell"
It would evaluate everything between the quotes as an exact mach with
exception to case sensitivity.


Greg Hill
Roland Wingerter
2008-12-08 17:29:27 UTC
Permalink
Post by Greg Hill
Post by Roland Wingerter
http://www.google.com/help/operators.html
That is a useful link.
I guess we all know about the + symbol that little guy can make searching
google a breeze.
--------
FWIW, searching Google.com was an example in Michael Nuwer's demo. But this
technique can also be used for other websites, if you can figure out the
parameters.

For example, I have written a cc using XMLhttpRequest which allows me to
send queries to our web application and parse the response as a quality
assurance measure.

Roland

Greg Hill
2008-12-07 22:39:07 UTC
Permalink
I know you resolved the issue but, there is another approach you might well
be aware of but I thought I would post it just in case.

In the following URL a search will be done for greg and the location to
search will be dbase.com

The results show all my activity in the newsgroup.

http://www.google.com/search?source=ig&hl=en&rlz=&q=greg+site%3Adbase.com&aq=f


So you get the idea of replacing 'greg' with what you want to search for and
the dbase.com with the site to search.

Greg Hill
Loading...