簡體   English   中英

查詢字符串參數中的斜杠?

[英]Slashes in a query string parameter?

如何將文件路徑作為查詢字符串參數發送?

這是我的字符串參數:

//domain/documents/Pdf/1234.pdf

我試過了:

    [HttpPost]
    [Route("documents/print/{filePath*}")]
    public string PrintDocuments([FromBody] string[] docs,string filePath)
    {
       .....
    }

但這不起作用,我想是因為參數開頭的雙斜線。

任何的想法?

如果像你說的那樣,整個字符串是參數而不是路由,則需要對其進行URL編碼。 無論如何你應該總是這樣做:

System.Net.WebUtility.UrlEncode(<your string>);
// %2F%2Fdomain%2Fdocuments%2FPdf%2F1234.pdf

更新

由於這不起作用,我建議您使用Base64編碼而不是URL編碼:

var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(<your string>);
var encodedFilePath = System.Convert.ToBase64String(plainTextBytes);

..並在你的控制器解碼它:

byte[] data = Convert.FromBase64String(filepath);
string decodedString = Encoding.UTF8.GetString(data);
System.Web.HTTPUtility.UrlEncode(@"//domain/documents/Pdf/1234.pdf")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM