c# - Cyrillic symbols in HttpClient POST request for upload filename -
in 1 of .net applications i've go method uploads file site via httpclient. here implementation
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; } } }
method work fine. when pass cyrillic symbols in filename property generated post request filename has corrupted symbols ????1.docx exmaple ? replaces cyrillic symbol. there way send cyrillic symbols without corruption?
i believe filename
limited on can in terms of code page. guess supports ascii (not 100% sure). there better header can use called filename*
bit hard google since google remove *
, ordinary filename
back.
long story short need use this:
$"filename*=utf-8''{filename}"
you might need encoding of filename regard space, etc. can google bit more on + check post.
p.s. older browsers might not it, need check requirements.
Comments
Post a Comment