【发布时间】:2020-07-13 20:09:02
【问题描述】:
public ActionResult Index(PublishPost post, HttpPostedFileBase file)
{
var apiURL = "http://test.sa.com/rest/social/update/1161/upload?access_token=6fWV564kj3drlu7rATh8="
WebClient webClient = new WebClient();
byte[] responseBinary = webClient.UploadFile(apiUrl, file.FileName);
string response = Encoding.UTF8.GetString(responseBinary);
/* Giving error here. How to proceed?
}
我想上传一个文件到这个url,响应如上图所示。如何在 C# 中进一步处理相同的问题?请帮忙
【问题讨论】:
-
尝试使用 fiddler 在客户端和服务器之间的通信中达到峰值。可能会提示发生了什么问题(例如,发送数据的方式存在问题,或者 http 错误代码在 fiddler 中比尝试调试更容易解释)。请发布结果。
-
使用 api 调用上传文件的简单方法是将文件转换为 base64 字符串并在服务器上发送字符串,然后在服务器端将 base64 字符串转换为文件并存储在目录中。
标签: asp.net asp.net-mvc rest asp.net-mvc-4 asp.net-web-api