.csv 파일을 업로드 할 수 있도록 내 서버에 API 호출을 만들려고합니다.C# setting uploadFile content-Type
클라이언트 측 코드
string url = "http://testserver/testapi";
string filePath = @"C:\test.csv";
using (WebClient wc = new WebClient())
{
wc.Headers.Add("Content-Type", "text/plain");
byte[] responseArray = wc.UploadFile(url, filePath);
}
서버 측 코드
string savePath = testSavePath;
foreach (string f in Request.Files.AllKeys)
{
HttpPostedFileBase file = Request.Files[f];
file.SaveAs(savePath);
}
나는이 줄에 예외를 얻고있다 byte[] responseArray = wc.UploadFile(url, filePath);
이상한 것은 내가 Request
볼 때 나는
ContentType="multipart/form-data; boundary=---------------------8d006b7c2a5452c"
.
WebException이이 The Content-type header begins with multipart.
내 질문은 왜 contentType이 여러 부분으로 설정지고 있습니다 때 발생합니다 그리고 내가 그렇게에서 어떻게 방지 할 것을 내가 볼을 UploadFile에 대한 문서를 보면?
예외는 무엇입니까? –
'wc.Headers.Add ("Content-Type", "text/plain");을 제거하면 작동합니까? –