【发布时间】:2015-05-26 05:50:56
【问题描述】:
public ActionResult Index(PublishPost post, HttpPostedFileBase f)
{
string apiUrl = "http://myurl.com"
WebClient Client = new WebClient();
byte[] rb = Client.UploadFile(apiUrl, "POST", f.FullName);
string response = Encoding.UTF8.GetString(rb);
}
httppostefilebase 的路径正在显示 -- C:\Windows\SysWOW64\inetsrv\adminrights.JPG 但它在 webclient 上出现错误 - Path not found。请帮忙
【问题讨论】:
-
您是在本地测试还是在某些服务器上测试?如果
string apiUrl = "http://myurl.com"是某个服务器 URL,并且您正在上传存储在本地的文件,它将无法正常工作。你应该使用using (var fileStream = File.Create(BasePath + FolderName + fileName)) { f.InputStream.CopyTo(fileStream); } -
您是否在 iis 上托管了您的网站??
-
@Kamo 如果我创建一个文件,那么我也必须删除它,对吗?你能写一个同样的例子吗,我也应该在 app_code 文件夹或其他文件夹中创建文件吗?
-
@rohitsingh 删除文件阅读此msdn.microsoft.com/en-us/library/…
标签: c# asp.net-mvc asp.net-mvc-4 file-io webclient