POST请求从ASP.NET另一个URL [英] Post request to another URL from ASP.NET
问题描述
我想在那里创建ASP.NET页面,将发送请求给另一个非ASP.NET URL,并检查什么的,在我的情况下,它是检查,是域名免费的,或者它已经在使用。 (方法= POST)因此,我希望得到一个HTML code,我从中会提取因此,使用正则表达式。最后一部分,我可以做自己:)))
您可以使用的 WebClient的来发送POST请求,并获取远程资源的内容:
使用(VAR的客户=新的WebClient())
{
VAR值=新的NameValueCollection
{
{参数1,值1},
{参数2,值2},
};
字节[]结果= client.UploadValues(http://example.com/foo,值);
// TODO:处理结果
}
我从中会提取因此,使用正则表达式。最后一部分,我可以做自己:)
块引用>我希望你知道关于<一个普遍的看法href=\"http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454\">parsing HTML与正则表达式。所以,即使你可以自己做,不这样做。使用HTML解析器如 HTML敏捷性包来处理结果。
I want to create a page in ASP.NET which will, send request to another non ASP.NET URL, and check something there, in my case it is to check, is the domain name free, or it is already in use. (Method = POST) As a result i want to get an HTML code, from which i will extract a result, using RegEx. The last part, I can do myself :)))
解决方案You could use a WebClient to send a POST request and fetch the contents of a remote resource:
using (var client = new WebClient()) { var values = new NameValueCollection { { "param1", "value 1" }, { "param2", "value 2" }, }; byte[] result = client.UploadValues("http://example.com/foo", values); // TODO: process the results }
from which i will extract a result, using RegEx. The last part, I can do myself :)
I hope you are aware about the general opinion on parsing HTML with Regex. So even if you can do this yourself, don't do it. Use a HTML parser such as HTML Agility Pack to process the results.
这篇关于POST请求从ASP.NET另一个URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!