0
我在PHP論壇上使用C#代碼嘗試認證用戶時遇到了問題。 到目前爲止,我嘗試:使用C#.NET進行PHP論壇認證
webClient.Credentials = new NetworkCredential("Me", "MyPassword");
則:
HtmlDocument webPage = new HtmlDocument();
webPage.Load(new MemoryStream(client.DownloadData(this.websiteUri)));
我也累加的cookie信息,以Web客戶端頭。
而且我想:
using (WebClient client = new WebClient())
{
byte[] response = client.UploadValues(url, new NameValueCollection()
{
{ "usrname", "myLogin" },
{ "password", "[email protected]" }
});
string result = System.Text.Encoding.UTF8.GetString(response);
}
如何,我可以檢查的結果? 我在做什麼錯誤?有什麼建議麼?
謝謝!
好吧,我試過了。在遵循你的建議之後,我沒有從login.php重定向到主論壇頁面(響應URI是相同的) - 我認爲這是不正確的。我應該重定向,所以響應URI應該是:「home.php」。 此外 - 我每次檢查URL時是否被迫使用這個認證方法? – Luke 2015-02-09 19:04:52
重定向可能取決於服務器使用的方法。檢查響應標題,它們可能包含標題「Location:some-address.php」。這是POST請求後重定向到其他頁面的常用方式。 其次,如果你想保持登錄狀態,你需要保存cookies,它應該包含你的php會話。在這裏你有一些技巧如何做到這一點:http://www.codeproject.com/Articles/195443/WebClient-Class-with-Cookies http://stackoverflow.com/questions/1777221/using-cookiecontainer-with-webclient -類 – 2015-02-09 21:19:02