我正在使用RestSharp的AddFile,它的工作接近于正常,除了我的文件因为正在添加的头信息而最终破坏。RestSharp AddFile将多部分表单头文件添加到文件
-------------------------------28947758029299
Content-Disposition: form-data; name="user.png"; filename="user.png"
Content-Type: image/png
这只是我上传的测试图片。如果我从文件中删除这些行然后它打开罚款,否则它似乎是腐败的。 没有这个东西得到添加,我可以使用AddFile吗?
当前代码:
string contentType = MimeMapping.GetMimeMapping("~/uploads/" + filename); //image/png etc
request.AddFile(filename, Server.MapPath("~") + "\\uploads\\" + filename, contentType);
IRestResponse response = client.Execute(request);
而且具有相同的结果试过这样:
request.AddHeader("Content-Type", contentType);
byte[] bytes = File.ReadAllBytes(Server.MapPath("~") + "\\uploads\\" + filename);
request.AddBody(new {myFile = File.ReadAllBytes(Server.MapPath("~") + "\\uploads\\" + filename) });
而且这个(没有文件所经历的一切都在这里):编辑:这实际工作
string contentType = MimeMapping.GetMimeMapping("~/uploads/" + filename);
byte[] bytes = File.ReadAllBytes(Server.MapPath("~") + "\\uploads\\" + filename);
request.AddHeader("Content-Type", contentType);
request.AddParameter(contentType, bytes, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
使用zendesk api,如果有人很好奇我在上传到 – abney317