Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft.XMLHTTP 1

Status
Not open for further replies.

fayna

Programmer
Jan 14, 2002
35
ES
Hi,
I'm trying to save a web page content by using Microsoft.XMLHTTP. I can write it into a new page but I get an error when I write it in a file.Here's my code:
Response.Buffer = True
Dim objXMLHTTP, xml,strHtmlText
Dim FSO,objFile,f
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", Request.ServerVariables("HTTP_REFERER"), False
xml.Send
Response.Write xml.responseText 'It really works!!
Set FSO = Server.CreateObject("Scripting.FileSystemObject")f = "myFile.html"
Set objFile=fso.CreateTextFile(server.MapPath(f))objFile.Write(xml.responseText )'Here I get an error saying:wrong argument or wrong procedure calling
objFile.Close
Set xml = Nothing

Where's the error?
Thank you
 
try:
Set FSO = Server.CreateObject("Scripting.FileSystemObject")f = "myFile.html"
Set objFile=fso.CreateTextFile(server.MapPath(f))objFile.Write("ASD")

Known is handfull, Unknown is worldfull
 
For server side script you should use the server-safe version of xmlhttp.
 
PS: You can use the server-safe version just like the old one, the only thing you need to change is the string used to create the object.

So try this: "MSXML2.ServerXMLHTTP"

 
I am not sure if "xml" is a reserved word. Try using "objXML" or something like that.

Regards
Satihs
 
Fayna,
Did you resolve this? I am getting the same error that you are getting on the 3rd line from the bottom. I am sure it is because I am trying to place a variable value into the file rather than text with quotes.

Example:
objFile.Write(xml.responseText ) does not wrok
objFile.Write("add this text") DOES work..

How do/did you fix this??

Dave
 
I think I got a bit more info... The page I am trying to save contains quotes. I think they are confusing the textstream.write command...

Does that make sense?
 
I ran the code that fayna has posted above and it was quite fine. I am running Win XP IIS. It could be that when your HTTP_REFERER has nothing this error is showing.

It does not seem like a double or single quotes problem as I put them in my HTML and it was fine.

Regards
Satish
 
Dave,

Yes I am getting the error. Considering your earlier message that it could be due to double quotes, I did a
Code:
Server.HtmlEncode(xml.ResponseText)
and though I did not get the error and data was written to the HTML it was written as text with the HTML tags converted into > & lt; etc.

Regards
Satish
 
Good idea, but that kind of defeats the point. I need to have functional HTML pages. Any ideas?

At least we know the issue lies within the code being grabbed...
 
Dave

I ran the same script but changed the URL to something more generic i.e. a more popular URL and it was fine.

Now am not sure if this is making a difference but if you look down to it is showing an ASP error at the end page.

Maybe..just maybe...that is causing the error in your code too.

Regards
Satish
 
I think I've got it!!!

The page we are looking at has a question mark on it. I tried a page that does not, and it WORKED!!!

Now, how do I get around this without going through the entire database and getting rid of question marks. In addition, I wonder if any other special characters will be a problem...
 
I've GOT IT now!

it turns out that this record had a "registered trademark" character. The "R" with a circle around it. In the title. When the xmlhttp function processed it, it displays a "?" in its place on an output of the xml.responsetext

aka: response.write xml.responsetext

I took that character out of the DB, and it works!

I wonder what other characters we may have in the DB that may screw this up.

Anyway, I think I've got it from here. THANKS!

Dave
 
Dave

I am glad it worked. But I may have found one more work around. I think it can be solved if we use the right charset too. Try adding these lines of code:
Code:
xml.Open "POST", "[URL unfurl="true"]http://www.truckmod.com/partsdisplay.asp?part=900979",[/URL] False
xml.SetRequestHeader "Content-type", "application/x-[URL unfurl="true"]www-form-urlencoded;charset=utf-8"[/URL]

I tried this and it worked.

Regards
Satish
 
Am I missing something? Either I go to the page directly or using xmlhttp to grab it, I've got the same error:
[tt] ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
/partsdisplay.asp, line 386 [/tt]
 
Thanks Satish for the supplementary info. Your post above seems promising. Will take a little study on it. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top