Path.Combine for URLs?(用于 URL 的 Path.Combine?)
问题描述
路径.合并 很方便,但在 .NET 框架中是否有类似的功能用于 URLs?
Path.Combine is handy, but is there a similar function in the .NET framework for URLs?
我正在寻找这样的语法:
I'm looking for syntax like this:
Url.Combine("http://MyUrl.com/", "/Images/Image.jpg")
会返回:
http://MyUrl.com/Images/Image.jpg"
推荐答案
有是一个上面 Todd Menier 的评论 说 Flurl 包含一个 Url.Combine代码>.
There is a Todd Menier's comment above that Flurl includes a Url.Combine
.
更多细节:
Url.Combine 基本上是 URL 的 Path.Combine,确保一个部分之间只有一个分隔符:
Url.Combine is basically a Path.Combine for URLs, ensuring one and only one separator character between parts:
var url = Url.Combine(
"http://MyUrl.com/",
"/too/", "/many/", "/slashes/",
"too", "few?",
"x=1", "y=2"
// result: "http://www.MyUrl.com/too/many/slashes/too/few?x=1&y=2"
在 NuGet 上获取 Flurl.Http:
Get Flurl.Http on NuGet:
PM> 安装包 Flurl.Http
PM> Install-Package Flurl.Http
或者获取独立的 URL 构建器,没有 HTTP 功能:
Or get the stand-alone URL builder without the HTTP features:
PM> 安装包Flurl
PM> Install-Package Flurl
这篇关于用于 URL 的 Path.Combine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于 URL 的 Path.Combine?


基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01