使用C#将文件上传到远程URL [英] Uploading a file to remote url using c#
本文介绍了使用C#将文件上传到远程URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在尝试使用c#在我的网站上上传文件
到目前为止,我已经编码了html/php文件,以允许用户在网站上上传数据
这是
链接 [
hello i''m trying to upload a file on my website using c#
so far i have coded html/php files to allow users to upload data on the website
here''s the
link[^]
to the website.
the function i made in c# to upload files is:
public void Upload_file()
{
WebClient client = new WebClient();
string url = "http://gh0st.x10.mx/JS/Upload/upload.html";
string filename = @"C:\ReadMe.txt";// @"C:\myfolder\MyVideo" + counter + ".avi";
try
{
client.UploadFile(url, filename);
}
catch (Exception x1)
{
MessageBox.Show(x1.ToString());
}
}
它没有显示任何内容..没有错误..并且没有文件上传到网站上.
我究竟做错了什么?请帮助
p.s是初学者.
and it doesn''t show anything .. no error..and no file is uploaded on the website.
what am i doing wrong? please help
p.s im a beginner.
推荐答案
在使用multipart-formdata时,WebClient似乎不合适. 尝试使用HttpWebRequest-Class或将上载字段的名称更改为文件".
您可以通过在脚本的开头执行print_r(
As you are using multipart-formdata the WebClient seems to be unsuitable.
Either try to use the HttpWebRequest-Class or adapt the name of the upload-field to "file".
You can test the last one by do a print_r(
_FILES)来测试最后一个.
_FILES) at the beginning of the script.
这篇关于使用C#将文件上传到远程URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文