要做到这一点,首先需要知道服务器是如何接受,因为你必须输入用户名和密码,这是最有可能是由POST方法的请求,那么你将获得的输入可以是字符串使用 一些浏览器扩展名获得,如Live Http Headers。 它应该是这个样子
http://yourwebsite/extension
POST /extension HTTP/1.1
Host: yourwebsite
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Length: 85
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive
HereShouldBeThePoststring
然后,你将创建一个HttpWebRequest的使用本网站的URL
using System.Net;
string postUrl = "YourWebsiteUrlWithYourExtension";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postUrl);
那么你会发布数据
string postString = "ThePostStringYouObtainedUsingLiveHttpHeaders";
request.Method = "POST";
byte[] Content = Encoding.ASCII.GetBytes(postString);
request.ContentLength = Content.Length;
using (Stream stream = request.GetRequestStream())
{
stream.W
,那么你会得到响应串
string responsestring = null;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
responsestring = reader.ReadToEnd();
}
那么你会分析你的字符串来获取数据您的需要。 解析的好库是Html Agility Pack。
为什么'php'标签在这里?你应该打电话给哪个API? –
所以你想从Windows窗体调用该网站? – CodingYoshi
这里尝试http://stackoverflow.com/questions/4088625/net-simplest-way-to-send-post-with-data-and-read-response看 – Beginner