分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

上传图片到第三方服务器

发布时间:2023-09-06 02:20责任编辑:沈小雨关键词:上传图片

代码

/// <summary> ???/// 上传图片到第三方服务器 ???/// </summary> ???/// <param name="filePath"></param> ???/// <param name="picNo"></param> ???/// <returns></returns> ???public string UploadFilesToBlueBox(string filePath, string picNo) ???{ ???????string strReturn = ""; ???????string fileName = Path.GetFileName(filePath); ???????string strPostUrl = "http://pic.xxx.com/HttpPost_Upload.aspx?PICID=" + picNo + "&FILENAME=" + fileName; ???????HttpWebRequest reqPost = (HttpWebRequest)WebRequest.Create(strPostUrl); ???????reqPost.Method = "POST"; ???????reqPost.KeepAlive = false; ???????reqPost.ContentType = "application/x-www-form-urlencoded"; ???????byte[] fileStream = AuthGetFileData(filePath);//把文件转为bute[],看之前的博客 ???????string strStream = Convert.ToBase64String(fileStream); ???????byte[] strFiledata = Encoding.UTF8.GetBytes(strStream); ???????reqPost.ContentLength = strFiledata.Length; ???????//post数据 ???????using (Stream newStream = reqPost.GetRequestStream()) ???????{ ???????????newStream.Write(strFiledata, 0, strFiledata.Length); ???????????//获取返回 ???????????HttpWebResponse myResponse = (HttpWebResponse)reqPost.GetResponse(); ???????????using (StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8)) ???????????{ ???????????????//返回结果 ???????????????strReturn = reader.ReadToEnd(); ???????????} ???????} ???????return strReturn; ???}

上传图片到第三方服务器

原文地址:https://www.cnblogs.com/xsj1989/p/9884752.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved