HopkinsProg Posted November 15, 2008 Posted November 15, 2008 Hey guys, perhaps you can help me with a small issue I'm having.My goal is to use wininet.dll to submit POST variables to a webpage and download the contents of an XML file in return.I can successfully submit my variables and I have my XML returned in string form. I would like to keep this in string form, inside the AutoIT script, but I have not found any methods that can directly parse a string, they can only parse files.So, with a file temporarily created, using AutoIT's FileWrite() function, I am using the XMLDomWrapper script found elsewhere in the forums to parse the XML file.However, for whatever reason, the string have is not correctly formatted. It looks exactly as I want it to:<?xml version="1.0"?><output><msg>Hello World!</msg></output>But, when i pass it to the XML parser, the _GetFirstValue function fails to parse the string, returning 0.If I manually type in the contents of the file (vs downloading it from the internet), it works perfectly.Do you all have any suggestions as to why the string I am getting from my webpage looks okay, but for whatever reason will not work when run through the XML parser?If you know of a way that I can directly parse my string, without having to save a file, that would be the best solution for me.You assistance is much appreciated. Thank you!
Prab Posted November 15, 2008 Posted November 15, 2008 You might want to look at _StringInsert(), StringReplace(), and StringRegExpReplace(). I have used all of them to edit strings in my scripts. (I have never used the XMLDomWrapper, so I don't know if these directly apply.) FolderLog GuiSpeech Assist
weaponx Posted November 15, 2008 Posted November 15, 2008 There is an undocumented function in the XML Dom Wrapper called _XMLLoadXML. See if that works for you.
HopkinsProg Posted November 15, 2008 Author Posted November 15, 2008 That would be perfect, but I'm still having issues. If I pass a hand-typed string, it works perfectly. But, if I pass the output from the web page, it crashes the function call with the attached error message. So you all can see what I'm doing, here's the relevant code: expandcollapse popup#include <guiconstants.au3> #include "WinINet.au3" #Include <_XMLDomWrapper.au3> HotKeySet("{ESC}", "Terminate") DllOpen("wininet.dll") $internet = _WinINet_InternetOpen("Mozilla") If $internet == 0 Then MsgBox(0, "Error", "Setup Error") EndIf $internetconnect = _WinINet_InternetConnect($internet, $INTERNET_SERVICE_HTTP, "mydomain.com", "80") If @error Then MsgBox(0, "Error", "Error connecting to the internet.") $data = "field=value"&@CRLF $type = "Content-Type: application/x-www-form-urlencoded"&@CRLF $agent = "User-Agent: Mozilla/4.0"&@CRLF $newdata = $agent & $type $httprequest = _WinINet_HttpOpenRequest($internetconnect, "POST", "/getxml.php") $addheader = _WinINet_HttpAddRequestHeaders($httprequest, $newdata, $HTTP_ADDREQ_FLAG_ADD) ConsoleWrite($addheader & @CRLF) $sendrequest = _WinINet_HttpSendRequest($httprequest,Default,StringToBinary($data)) local $readfile = Binary("") Do $readfile &= _WinINet_InternetReadFile($httprequest, 5000) Until @error<>0 Or Not @extended $loadedXML=_XMLLoadXML($readfile) ConsoleWrite("XMLLoadXML: "&$loadedXML&@CRLF) $myMsg=_GetFirstValue("/output/msg") msgbox(64,"INFO",$myMsg) Exit
weaponx Posted November 15, 2008 Posted November 15, 2008 It might have to do with the encoding of the returned data. Maybe you can specify a content type for xml in the return request? "Content-Type", "text/xml"
HopkinsProg Posted November 15, 2008 Author Posted November 15, 2008 (edited) Yep, already delivered as text/xml. Even tried text/plain. I've checked the source in browsers, and it looks perfect. x-(Must be something else wrong with it...Edit:*facepalm* Yeah... I forgot to convert it back from binary... whoops... Thanks for the help with the rest of it guys! Edited November 15, 2008 by HopkinsProg
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now