์๋ ,
v105.2.3์์ ๋ฉํฐํํธ ์ ๋ก๋ ์์ ์ ์ํํ๋ ค๊ณ ํ๋๋ฐ Content-Length์ ๋ฌธ์ ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
using (FileStream source = File.Open(path, FileMode.Open))
{
RestSharp.RestRequest request2 = new RestSharp.RestRequest();
request.Resource = $"/files/uploads/{UploadId}";
request.Method = Method.POST;
request.AddFile(filename, source.CopyTo, filename);
request.AlwaysMultipartFormData = true;
IRestResponse<UploadResponse> response2 = this.Client.Execute<UploadResponse>(request);
if ((int)response2.StatusCode != 201)
{
throw new Exception(response2.StatusDescription);
}
}
response2์๋ ๋ค์๊ณผ ๊ฐ์ ์ค๋ฅ ๋ฉ์์ง๊ฐ ์์ต๋๋ค(๋
์ผ์ด๋ก ๋์ด ์์ผ๋ฉฐ ์์ฒญ์ด ์ทจ์๋์์์ ์๋ฏธํฉ๋๋ค.):
_Die Anfrage wurde abgebrochen: Die Anfrage wurde abgebrochen.._
๋ด๋ถ ์์ธ(๋ชจ๋ ๋ฐ์ดํธ๊ฐ ๊ธฐ๋ก๋ ๋๊น์ง ์คํธ๋ฆผ์ ๋ซ์ ์ ์์):
_Stream kann nicht geschlossen werden, bevor alle Bytes geschrieben wurden._
Fiddler์์ ๋๋ ์ด๊ฒ์ ์ป์ต๋๋ค.
์์ฒญ - ์ํฐํฐ
Content-Length: 210
Content-Type: multipart/form-data; boundary=-----------------------------28947758029299
์๋ต
HTTP/1.1 408 Request body incomplete
The request body did not contain the specified number of bytes. Got 159, expected 210
์ด ๋ฒ์ ์ด ํ์ํ ๋ค๋ฅธ ํจํค์ง(์: RestSharp.Newtonsoft.Json)๊ฐ ์์ผ๋ฏ๋ก ์ด ๋ฒ์ ๊ณผ ํจ๊ป Nuget ํจํค์ง๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
์ฌ๊ธฐ์ ๊ฐ์ ๋ฌธ์ ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
https://github.com/restsharp/RestSharp/issues/742
์น์ ํ๋,
์๋ ์ค
์๋ ์๋ ์ค,
๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ํด๊ฒฐํ๊ฑฐ๋ ํด๊ฒฐํ์ต๋๊น?
์น์ ํ๋,
๋ชจ๋ฆฌ์ธ
๋๋ ์ด์ ๋์ผํ ๋ฌธ์ ๊ฐ ์์๊ณ ๋ค์๊ณผ ๊ฐ์ด AddFile() ๋์ request.Files.Add() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ํด๊ฒฐํ์ต๋๋ค.
request.Files.Add(new FileParameter
{
Name = "fileAttach",
Writer = (s) =>
{
FileStream stream = File.Open(_attachment.path, FileMode.Open);
stream.CopyTo(s);
stream.Dispose();
},
FileName = _attachment.name,
ContentType = _attachment.contentType,
ContentLength = _attachment.size
});
AddFile
์ฌ์ฉํ ์ ์์ง๋ง ๋ด์ฉ ๊ธธ์ด๋ฅผ ์ง์ ํด์ผ ํ๋ฉฐ ์ด์ ๋ํ ๋งค๊ฐ๋ณ์๊ฐ ์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ ์ด์ ๋์ผํ ๋ฌธ์ ๊ฐ ์์๊ณ ๋ค์๊ณผ ๊ฐ์ด AddFile() ๋์ request.Files.Add() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ํด๊ฒฐํ์ต๋๋ค.