C# ,想通过Winform将图片上传到网络上。有没有事什么办法?
展开全部
/// <summary>
/// 传文件到服务器
/// </summary>
/// <param name="url"></param>
/// <param name="Path"></param>
public static string UpLoadFile(string url, string Path)
{
try
{
WebClient myWebClient = new WebClient();
Uri uri = new Uri(url);
byte[] by = myWebClient.UploadFile(uri, "POST", Path);
string returnStr = Encoding.UTF8.GetString(by);
return returnStr;
}
catch (Exception ex)
{
MessageUtil.ShowWarning(ex.Message);
}
return "";
}
/// 传文件到服务器
/// </summary>
/// <param name="url"></param>
/// <param name="Path"></param>
public static string UpLoadFile(string url, string Path)
{
try
{
WebClient myWebClient = new WebClient();
Uri uri = new Uri(url);
byte[] by = myWebClient.UploadFile(uri, "POST", Path);
string returnStr = Encoding.UTF8.GetString(by);
return returnStr;
}
catch (Exception ex)
{
MessageUtil.ShowWarning(ex.Message);
}
return "";
}
更多追问追答
追问
抱歉,我的函数返回的是一个bool类型的数据,你return的 字符串是用来干什么的?
追答
上传到服务器,接受服务器返回的数据
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询