本文介绍了使用C#将文件上传到远程URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在尝试使用c#在我的网站上上传文件 到目前为止,我已经编码了html/php文件,以允许用户在网站上上传数据 这是 链接 [ ^ ] 进入网站. 我在C#中上传文件的功能是:
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 = "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
发布评论