从Web浏览器控件发布查询 [英] Post query from web browser control
本文介绍了从Web浏览器控件发布查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在C#应用程序中托管Web浏览器控件
网站我正在导航以在点击链接时发送POST并且它以JSON接收一组结果。
有什么方法可以发送POST请求代表浏览器控件还是有浏览器接收和处理响应?好像用户点击了链接...
提前感谢您的帮助!
Hello all,
I am hosting a web browser control within a C# application
The website I am navigating to sends a POST upon clicking a link and it receives a set of results in JSON.
Is there any way that I can send the POST request on behalf of the browser control and still have the browser receive and process the response? As if the user had clicked the link...
Thanks in advance for any assistance!
推荐答案
基本上,我可以看到两种不同的可能性。
首先,您可以使用WebBrower中提供的页面发送HTTP请求
控件实例,使用Javascript和Ajax: http://en.wikipedia.org/wiki/Ajax_%28programming %29 [ ^ ]。
一种非常方便的方法是使用jQuery.Ajax()
:
< a href =http://api.jquery.com/jquery.ajax> http://api.jquery.com/jquery.ajax [ ^ ]。
此外,您可以直接发送HTTP请求,在WebBrowser
之外,使用System.Net.HttpWebR的实例equest
:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=vs.110%29.aspx [ ^ ]。
然后,您可以接收HTTP响应,如果需要则解析它,并使用此数据直接修改WebBrower实例的DOM树
。
不幸的是,您无法始终自由地混合来自不同实例的请求。例如,如果使用HttpWebRequest
实例执行身份验证,则不能假定Web应用程序将浏览器的客户端视为已通过身份验证;这将是一个不同的会议。
-SA
Basically, I can see two different possibilities.
First, you can send HTTP request using the page presented in theWebBrower
control instance, using Javascript and Ajax: http://en.wikipedia.org/wiki/Ajax_%28programming%29[^].
A very convenient way would be using jQuery.Ajax()
:
http://api.jquery.com/jquery.ajax[^].
Also, you can send an HTTP request directly, outside ofWebBrowser
, using the instance ofSystem.Net.HttpWebRequest
:
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=vs.110%29.aspx[^].
You can then receive HTTP response, parse it if it is required, and use this data to directly modify the DOM tree of your instance ofWebBrower
.
Unfortunately, you won't be always able to freely mix the requests from different instances. For example, if you perform authentication usingHttpWebRequest
instance, you cannot assume that the Web application treats your browser's client as authenticated; it will be a different session.
—SA
这篇关于从Web浏览器控件发布查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文