ashx图片上传接收
发送数据流方法 /// <summary>
/// PostBinaryData
/// </summary>
/// <param name="url">要发送的 url 网址</param>
/// <param name="bytes">要发送的数据流</param>
/// <returns></returns>
public string PostBinaryData(string url, byte[] bytes)
{
//下面是测试例子
//string url = "http://www.test.com/test.ashx";
//string img = HttpContext.Current.Server.MapPath("../images/test.jpg");
//byte[] bytes = File.ReadAllBytes(img);
HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(url);
wRequest.ContentType = "multipart/form-data";
wRequest.ContentLength = bytes.Length;
wRequest.Method = "POST";
Stream stream = wRequest.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
stream.Close();
HttpWebResponse wResponse = (HttpWebResponse)wRequest.GetResponse();
StreamReader sReader = new StreamReader(wResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string str = sReader.ReadToEnd();
sReader.Close();
wResponse.Close();
return str;
} public void GetBinaryData()
{
string imgFile = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
string filePath = HttpContext.Current.Server.MapPath(imgFile);
//方法一
int lang = HttpContext.Current.Request.TotalBytes;
byte[] bytes = HttpContext.Current.Request.BinaryRead(lang);
string content = System.Text.Encoding.UTF8.GetString(bytes);
FileStream fStream = new FileStream(filePath, FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fStream);
bw.Write(bytes);
bw.Close();
fStream.Close();
//方法二
Bitmap img = new Bitmap(HttpContext.Current.Request.InputStream);
img.Save(filePath);
HttpContext.Current.Response.Write("ok");
}
接收数据流方法
ashx图片上传接收的更多相关文章
- ashx 图片上传路径URL
ashx 图片上传 为了方便多出调用图片上传方法 首先我们将图片上传方法抽离出来 创建ashx 一个新的方法 using System; using System.Collection ...
- ashx 图片上传
为了方便多出调用图片上传方法 首先我们将图片上传方法抽离出来 创建ashx 一个新的方法 using System; using System.Collections.Generic; u ...
- .NET 图片上传接收类
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- bootstrap-fileinput 图片上传
bootstrap-fileinput 源文件 在网上下载 CSS: <link href="../../static/Bootstrap/css/plugins/bootstrap- ...
- asp.net 百度编辑器 UEditor 上传图片 图片上传配置 编辑器配置 网络连接错误,请检查配置后重试
1.配置ueditor/editor_config.js文件,将 //图片上传配置区 ,imageUrl:URL+"net/imageUp.ashx" //图片上传提交地址 ,im ...
- CKEditor不借助CKFinder实现图片上传(.net版 ashx实现)
参考博客:http://blog.csdn.net/mydwr/article/details/8669594 本人版本:4.4.6 打开文件:ckeditor/plugins/image/dialo ...
- 微信小程序开发之多图片上传+服务端接收
前言: 业务需求,这次需要做一个小程序同时选中三张图片一起上传到服务端,后端使用的.NET WEBAPI接收数据保存. 使用技术: 在这章中将会使用到微信小程序wx.uploadFile(Object ...
- [转]微信小程序开发(二)图片上传+服务端接收
本文转自:http://blog.csdn.net/sk719887916/article/details/54312573 文/YXJ 地址:http://blog.csdn.net/sk71988 ...
- ajax图片上传(asp.net +jquery+ashx)
一.建立Default.aspx页面 <%@ Page Language="C#" AutoEventWireup="true" CodeFile=&q ...
随机推荐
- .pages怎么在windows上打开?Windows下打开在Mac中编辑的.pages文件方法
.pages怎么在windows上打开?Windows下打开在Mac中编辑的.pages文件方法 1.最简单的方法是修改后缀名为.zip然后解压,解压后就可以看到一张图片,这个就是文档内容了. 2.更 ...
- ESB(Enterprise Service Bus)企业服务总线介绍
ESB(Enterprise Service Bus)企业服务总线介绍 ESB全称为Enterprise Service Bus,即企业服务总线.它是传统中间件技术与XML.Web服务等技术结合的产物 ...
- Python这么热,要不要追赶Python学习热潮?
Python这么热,要不要追赶Python学习热潮? Python 可以用来做什么?在我看来,基本上可以不负责任地认为,Python 可以做任何事情.无论是从入门级选手到专业级选手都在做的爬虫,还是W ...
- linux 环境RPM 安装MYSQL5.6
linux 环境RPM 安装MYSQL5.6 系统环境 CentOS7.2 1.关闭selinux 服务[SELinux是一种基于域-类型 模型(domain-type)的强制访问控制(MAC)安全系 ...
- SQL Server双机热备之后项目的FailOver自动连接
SQL Server配置数据库镜像后,可能有朋友们会比较有疑惑,你一下搞两个数据库出来,他们的ip地址都不一样,到时候数据库切换过去了,我的数据库的连接字符串可如何是好?难道还得在代码中去控制是连接哪 ...
- Selenium 常用定位对象元素的方法
常见定位对象元素的方法 在使用selenium webdriver进行元素定位时,通常使用findElement或findElements方法结合By类返回的元素句柄来定位元素.其中By类的常用定位方 ...
- sql注入(转载)
1.使用firefox浏览器(安装一个firebug插件)登录http://192.168.204.132/dvwa/login.php页面,使用admin/password 2.打开firebug工 ...
- Java用Gson遍历json所有节点
<dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</ar ...
- 使用My97DatePicker设置日期的属性示例
<td>交易日期:</td> <td colspan="3"> <input class="Wdate" id=&qu ...
- thinkphp 随笔
'TMPL_CACHE_ON' => false,//禁止模板编译缓存 'HTML_CACHE_ON' => false,//禁止静态缓存