调用从C#代码网页 [英] Call a webpage from c# in code
问题描述
我需要从我的.NET里机应用调用网页的方式。
I need a way of calling a web page from inside my .net appliction.
但我只想请求发送到网页,而不必担心的响应。
But i just want to send a request to the page and not worry about the response.
由于有些时候的反应可能需要一段时间,所以我不希望它挂机应用。
As there are times when the response can take a while so i dont want it to hang the appliction.
我在身边一直试图在Page_Load事件
I have been trying in side the page_load event
WebClient webC = new WebClient();
Uri newUri = new Uri("http://localhost:49268/dosomething.aspx");
webC.UploadStringAsync(newUri, string.Empty);
尽管其设置为异步,但它仍然接缝挂在页面不会完成呈现直到螺纹已经finsished
Even though its set to Async, it still seams to hang as the page wont finish rendering until the threads have finsished
推荐答案
多克,几乎是有,但每次我提出的任何请求在sepreate时间线程的页面仍然不会告发T渲染,直到所有的线程已运行完毕。
Doak, Was almost there, but each time I put any of the request in a sepreate thread the page still wouldn't render until all the thread had finished running.
我发现这是调整多克的方法,只是坚持超时在那里和吞咽错误的最好方法。
The best way I found was adjusting Doak's method, and just sticking a timeout in there and swallowing the error.
我知道它是一个黑客,但它的工作:P
I know its a hack but it does work :P
WebRequest wr = WebRequest.Create("http://localhost:49268/dostuff.aspx");
wr.Timeout = 3500;
try
{
HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
}
catch (Exception ex)
{
//We know its going to fail but that dosent matter!!
}
这篇关于调用从C#代码网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!