ကိုယ်ပိုင် WebProxy အတွက် proxy account ကို ထို object တွင်ထားပါ။ အခြား .NET credential properties များ၏လက်ခံသူက မတူပါ။

Propertyလက်ခံသူ
WebProxy.Credentialsထို object က ကိုယ်စားပြုသော proxy။
HttpClientHandler.Credentialsဦးတည်ရာ server။
DefaultProxyCredentialsProxy null နှင့် UseProxy true ဖြစ်သည့်အခါ စနစ်၏ default proxy။

ဤ .NET 10 ဥပမာက အတိအလင်းသတ်မှတ်သော proxy နှင့်၎င်း၏သီးသန့် account ကို ပေးသည်။

using System;
using System.Net;
using System.Net.Http;

string password = Environment.GetEnvironmentVariable("PROXY_PASSWORD")
    ?? throw new InvalidOperationException("Set PROXY_PASSWORD");

var proxy = new WebProxy("http://203.0.113.10:8080")
{
    Credentials = new NetworkCredential("proxy-user", password)
};

using var handler = new HttpClientHandler
{
    Proxy = proxy,
    UseProxy = true
};
using var client = new HttpClient(handler)
{
    Timeout = TimeSpan.FromSeconds(15)
};

using var response = await client.GetAsync("https://example.com/");
Console.WriteLine((int)response.StatusCode);

စာတမ်း endpoint ကို အစားထိုးပြီး operator ပေးသည့် account သုံးပါ။ Authentication မလိုသောစာရင်းတစ်ခုအတွက် စိတ်ကူး login မလိုပါ။ Handler ၏ Proxy ကို အတိအလင်းပေးထားသဖြင့် DefaultProxyCredentials သည် WebProxy.Credentials ၏အစား မဟုတ်ပါ။

UseDefaultCredentials ၏ scope ကလည်း object အလိုက်ဖြစ်သည်။ Handler ၏ server authentication နှင့် WebProxy ၏ proxy authentication က မတူပါ။ Process user account ပို့ခြင်းသည် 407 ၏ယေဘုယျအဖြေ မဟုတ်ပါ။

Authentication challenge ဆက်ရှိလျှင် အမှန်တကယ် scheme၊ ရွေးထားသော endpoint နှင့် client/handler instance ကို စစ်ပါ။ Proxy authentication က ဦးတည်ရာ TLS မတိုင်မီ ဖြစ်နိုင်သောကြောင့် ဝဘ်ဆိုက် Authorization header က မဖြေနိုင်ပါ။ ပံ့ပိုးမှုသည် handler၊ platform၊ service နှင့် deployment policy ပေါ်မူတည်ဆဲဖြစ်သည်။ Global Windows proxy ပြောင်းရန် မလိုပါ။

ဆက်စပ်ဆောင်းပါးများ