Created
April 4, 2017 15:02
-
-
Save kiyokura/88b716344b09e339a86a7917ecf4670c to your computer and use it in GitHub Desktop.
自動構成スクリプトを考慮してOSのプロキシ設定をとってくるコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
} | |
private void Button_Click(object sender, RoutedEventArgs e) | |
{ | |
var target = "https://hoge.fuga.example.com/hogehoge/"; | |
var proxyInfo = CheckProxy(target); | |
} | |
private ProxyInfo CheckProxy(string targetAddress) | |
{ | |
var targetUri = new Uri(targetAddress); | |
var proxyUri = (WebRequest.GetSystemWebProxy()).GetProxy(new Uri(targetAddress)); | |
if (proxyUri.Host == targetUri.Host) | |
{ | |
// ターゲットとPROXYのHostが同じならProxy無しと判断。 | |
return new ProxyInfo(false, null); | |
} | |
else | |
{ | |
// PROXYアリの場合はそのままセット | |
return new ProxyInfo(true, proxyUri); | |
} | |
} | |
public class ProxyInfo | |
{ | |
public bool IsUse { get; set; } | |
public Uri Uri { get; set; } | |
public ProxyInfo() | |
{ | |
} | |
public ProxyInfo(bool isUse, Uri uri) | |
{ | |
IsUse = isUse; | |
Uri = uri; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment