private void Download()
{
using (WebClient wcDownload = new WebClient())
{
try
{
string username = "deneme";
string password = "deneme";
webRequest = (HttpWebRequest)WebRequest.Create(txtUrl.Text);
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)";
webRequest.PreAuthenticate = false;
webRequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(username + ":" + password));
webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
webRequest.Headers.Add("Accept-Language: en-us,en;q=0.5");
webRequest.Headers.Add("Accept-Encoding: gzip,deflate");
webRequest.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
webRequest.KeepAlive = true;
webRequest.Headers.Add("Keep-Alive: 1000");
webRequest.ReadWriteTimeout = 320000;
webRequest.Timeout = 320000;
webRequest.AllowAutoRedirect = true;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Credentials = CredentialCache.DefaultCredentials;
webResponse = (HttpWebResponse)webRequest.GetResponse();
Int64 fileSize = webResponse.ContentLength;
strResponse = wcDownload.OpenRead(txtUrl.Text);
strLocal = new FileStream(txtPath.Text, FileMode.Create, FileAccess.Write, FileShare.None);
int bytesSize = 0;
byte[] downBuffer = new byte[2048];
while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
strLocal.Write(downBuffer, 0, bytesSize);
this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { strLocal.Length, fileSize });
}
}
finally
{
strResponse.Close();
strLocal.Close();
}
}
} C# Basic Authentication
7
●1.200
- 15-09-2013, 19:31:20Kimlik doğrulama veya yönetimden onay bekliyor.C# da htaccess loginli siteme bağlanıp ordan dosya indirmek istiyorum fakat fakat bir türlü login olmuyor.401 hatası veriyor.Normal şifresiz dosya indirmede problem yok o iniyor.Yardımcı olursanız sevinirim.
- 20-09-2013, 18:16:22O şekilde de denedim ama çözüm bulamadım.onekey15 adlı üyeden alıntı: mesajı görüntüle
- 20-09-2013, 18:20:56Normal tarayicida bu sekilde giris yapabiliyor musun?onekey15 adlı üyeden alıntı: mesajı görüntüle
HTC One X cihazımdan Tapatalk 4 ile gönderildi