Webclient上传文件问题 [英] Webclient uploadfile problem

查看:99
本文介绍了Webclient上传文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,只是尝试将文件上传到我的本地网络服务器以准备我的任务,并且我在上传一个非常小的文件时遇到问题 - 没有错误它只是没有到达服务器,目录服务器上的权限(我在故障排除时更改了它们)是针对整个世界的读/写(它是一个Apache服务器)所以我在寻求帮助 - 下载文件完美无缺。

这就是我的意思'尝试过



Hi all, just experimenting with uploading a file to my local web server in preparation for a task I have and I'm having problems uploading a very small file - no errors it just doesn't arrive at the server, the directory permissions on the server ( I changed them whilst troubleshooting ) are read / write for the whole world ( it's an Apache server ) so I'm asking for help - downloading files works perfectly.
Here is what I've tried

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace DownloadFile
{
    class DownloadFile
    {
        WebClient client;

        static void Main(string[] args)
        {
            String URLRoot = @"http://10.10.1.11/Downloads/Data/";
            String UploadFname = "File.txt";
            String Msg = "This is headed for the server";

            File.WriteAllText(UploadFname,Msg);

            String UploadFullPath = Path.Combine(URLRoot,UploadFname);

            DownloadFile df = new DownloadFile();
            df.client = new WebClient();
            
            if (File.Exists(UploadFname))
            {
                 df.client.UploadFile(UploadFullPath, UploadFname);
            }
            df.client.Dispose();
            Console.ReadKey();
        }
    }
}





我尝试了什么:



如上面的代码所示



What I have tried:

As shown in the code above

推荐答案

你误解了UploadFile的作用。它不会将文件保存到目标服务器,它只是将文件POST到URL,就好像它是表单提交一样;



You misunderstand what UploadFile does. It doesn't save the file to the target server, it simply POSTs the file to the url as if it had been a form submission;

<form action="upload.aspx">
    <input type="file" name="myfile"/>
</form>





所以你上传的网址已经成为一个页面,可以读取发布到它的文件并保存它们。



WebClient.UploadFile方法(字符串,字符串)(System.Net) [ ^ ]


这篇关于Webclient上传文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆