简体   繁体   English

如何从Windows App调用AJAX API函数?

[英]How to call AJAX API function from Windows App?

Some company is providing me with web-based API for using their services. 某公司向我提供基于Web的API,以使用其服务。 I have no problem calling this API functions from within web brower: 我从网络浏览器中调用此API函数没有问题:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<script type="text/javascript" 

src="http://someaddress.com?&key=somekey"></script>
<script type="text/javascript">
var object = new SomeObject();
object.SomeFunction();
</script>
</head> 

I am interested in return value of SomeFunction(). 我对SomeFunction()的返回值感兴趣。 How would I get this return value from windows application? 我如何从Windows应用程序获取此返回值?

You can use a tool like Firebug . 您可以使用Firebug之类的工具。 That will let you watch the actual HTTP requests, and step through the JavaScript. 这样您就可以观看实际的HTTP请求,并逐步执行JavaScript。 In combination, that will let you see where the return value comes from. 结合使用,您将可以看到返回值的来源。

Once you understand this, you can replicate the requests (and possibly parts of the JavaScript logic) in your Windows app using an appropriate HTTP client library. 了解这一点之后,您可以使用适当的HTTP客户端库在Windows应用程序中复制请求(可能还包括JavaScript逻辑的一部分)。

Note that this may be a violation of the TOS. 请注意,这可能违反了TOS。

You can embed web browser control in WinForm and return value from SomeFunction into some DOM element, then you can access that element from WinForm.WebBrowser1. 您可以将Web浏览器控件嵌入WinForm中,并将SomeFunction的值返回到某个DOM元素中,然后可以从WinForm.WebBrowser1访问该元素。

There are also javascript emulators available, I think you can even use JSCRIPT dll from c# but that may not work if SomeFunction() depends on DOM. 也有可用的javascript模拟器,我认为您甚至可以使用c#的JSCRIPT dll,但如果SomeFunction()依赖DOM,则可能无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM