[英]How to swap domain in any URL in C#
我們遇到了從多個位置(多個后端服務)聚合一堆 URL 並將它們返回給調用者的問題。 但是,實際上大多數這些 URL 都可以從一個公共域訪問,我們需要更改所有 URL,以便它們反映這一點。
換句話說,如果我有這些網址:
https://example.org/some/sub/path
http://123.example.net:798/and/yet/another?with=some%20params
https://wrong.again.it?id=1
我們需要一個好的算法來更改每個 URL 的域,以便它們都來自同一個源並最終如下所示:
https://my.domain.net/some/sub/path
http://my.domain.net/and/yet/another?with=some%20params
https://my.domain.net?id=1
我們還沒有找到一種干凈、優雅、高效的令人滿意的方式。
這是UriBuilder
的一個相當典型的用法:
var builder = new UriBuilder("http://foo/bar?baz");
builder.Host = "newhost";
Console.WriteLine(builder.Uri);
也有相應的Scheme
和Port
屬性用於重新映射它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.