我想创建一个API调用到我的服务器,让我上传.csv文件。
客户端代码
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"
纵观文档为UploadFile我看到,当引发WebException将被抛出The Content-type header begins with multipart.
我的问题是为什么得到的contentType设置为多,我如何阻止它这样做?