0
在我的一個.NET應用程序中,我已經通過HttpClient將文件上傳到網站。這裏是實施HttpClient的西里爾符號POST請求上傳文件名
using (var clientHandler = new HttpClientHandler
{
CookieContainer = cookieContainer,
UseDefaultCredentials = true
})
{
using (var client = new HttpClient(clientHandler))
{
client.BaseAddress = requestAddress;
client.DefaultRequestHeaders.Accept.Clear();
using (var content = new MultipartFormDataContent())
{
var streamContent = new StreamContent(new MemoryStream(fileData));
streamContent.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("form-data");
streamContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("name", "contentFile"));
streamContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("filename", "\"" + fileName + "\""));
streamContent.Headers.ContentType = new MediaTypeHeaderValue(contentType);
content.Add(streamContent);
HttpResponseMessage response = await client.PostAsync("/Files/UploadFile", content);
if (response.IsSuccessStatusCode)
{
return true;
}
return false;
}
}
}
方法工作正常。但是當我通過西里爾文符號在文件名屬性生成後請求文件名已損壞符號如???? 1.docx爲exmaple其中?取代西里爾文符號。有沒有任何方法可以發送西里爾文符號而不會發生訛誤?
可能是[this]的副本(https://stackoverflow.com/questions/19196258/url-cyrillic-encoding-issue-with-webbrowser-control) – user5226582