开发者

HTTP request with Windows script host (.hta)

开发者 https://www.devze.com 2023-01-14 21:52 出处:网络
I can\'t believe I\'m stuck here, but I can\'t seem to make a simple HTTP request using Windows script host or simple .hta file.

I can't believe I'm stuck here, but I can't seem to make a simple HTTP request using Windows script host or simple .hta file.

This is my code:

<script language="Javascript">
window.onload = function() {
    var http = CreateObject("Microsoft.XmlHttp");
};
</script>

When I start the .hta file I get a 开发者_StackOverflow中文版JavaScript error saying something like Object Expected.. this is very annoying since it's a trivial task and I can't really debug it.

Any idea how I can debug this stuff? Thanks.


It seems to me you should use

var http = new window.ActiveXObject("Microsoft.XMLHTTP");

or just

var http = new ActiveXObject("Microsoft.XMLHTTP");

inside of .hta file instead of CreateObject().

UPDATED: Hi Luca! I have not much place in comments and can post links not so good, so I appended my answer:

The error which you do from the code of your question is that you try use in JavaScript elements of other language. In VBScript exist CreateObject, but it is a feature of the VBScript language. In JScript/JavaScript you have to use new ActiveXObject instead.

Moreover you mentioned in your comments several times about cross domain problems, but never described what do you do. If you want a help about this subject you should include in your question more information about what do you do. Probably you can include code in WSH or C which worked and include the corresponding version of the .HTA file. It would be also helpful if you describes why you want to use .HTA file instead of WScript/CScript or PowerShell. In which scenario you want to use .HTA file?


your function simply creates the object and then destroys it. Try returning to an external variable or doing more in the function.

0

精彩评论

暂无评论...
验证码 换一张
取 消