使用C#将文件上传到远程URL

编程入门 行业动态 更新时间:2024-10-22 18:40:06
本文介绍了使用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

本文发布于:2023-10-12 17:13:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485353.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件上传   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!