1

「過負荷」ではない認証を必要とする Web サイト コンテンツに接続してダウンロードしようとしています。

オプションは次のとおりです。

  • ユーザー
  • ユーザー+パスワード、
  • ユーザー+パスワード+ドメイン

ユーザー+サブスクライバー+パスワードが必要です。この資格情報を渡すにはどうすればよいですか?

コード:

WebClient client = new WebClient();  
public void search()  
{  
        client.Credentials = new System.Net.NetworkCredential(username, subscriber, password); //not really exist  
        Byte[] pageData = client.DownloadData("https://example.com/");
...  
}
4

1 に答える 1

1

問題をどのように解決したか: WebClient クラスを改善した POST メソッドを使用しました。これは webclient に似ていますが、Cookie を保存するものです。ここで見つけることができます。
コード:

ImprovedWebClient wc = new ImprovedWebClient();
wc.DownloadData("https://theWebSite.com"); //to enter home page and get cookie
string URI = "https://theWebSite.com/authenticate"; //the login page
string myParameters = "user=theUserName&subscriber_number=1234-5678&password=myPassword&commit=LogIn"; //the parameters for the website
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.UploadString(URI, myParameters);

助けてくれてありがとう。

于 2013-03-13T08:41:45.790 に答える