发送数据流方法

/// <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图片上传接收的更多相关文章

  1. ashx 图片上传路径URL

    ashx 图片上传   为了方便多出调用图片上传方法       首先我们将图片上传方法抽离出来 创建ashx 一个新的方法 using System; using System.Collection ...

  2. ashx 图片上传

    为了方便多出调用图片上传方法       首先我们将图片上传方法抽离出来 创建ashx 一个新的方法 using System; using System.Collections.Generic; u ...

  3. .NET 图片上传接收类

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  4. bootstrap-fileinput 图片上传

    bootstrap-fileinput 源文件 在网上下载 CSS: <link href="../../static/Bootstrap/css/plugins/bootstrap- ...

  5. asp.net 百度编辑器 UEditor 上传图片 图片上传配置 编辑器配置 网络连接错误,请检查配置后重试

    1.配置ueditor/editor_config.js文件,将 //图片上传配置区 ,imageUrl:URL+"net/imageUp.ashx" //图片上传提交地址 ,im ...

  6. CKEditor不借助CKFinder实现图片上传(.net版 ashx实现)

    参考博客:http://blog.csdn.net/mydwr/article/details/8669594 本人版本:4.4.6 打开文件:ckeditor/plugins/image/dialo ...

  7. 微信小程序开发之多图片上传+服务端接收

    前言: 业务需求,这次需要做一个小程序同时选中三张图片一起上传到服务端,后端使用的.NET WEBAPI接收数据保存. 使用技术: 在这章中将会使用到微信小程序wx.uploadFile(Object ...

  8. [转]微信小程序开发(二)图片上传+服务端接收

    本文转自:http://blog.csdn.net/sk719887916/article/details/54312573 文/YXJ 地址:http://blog.csdn.net/sk71988 ...

  9. ajax图片上传(asp.net +jquery+ashx)

    一.建立Default.aspx页面 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile=&q ...

随机推荐

  1. 项目方说性能达到百万TPS,如何测试它的可信度?

    项目方说性能达到百万TPS,如何测试它的可信度? 应用系统性能提升的关键在于运维端的接入管理模型(AAA,认证 Authentication.授权 Authorization.计费 Accountin ...

  2. 1069: 统计字符gets函数

    题目描述 编制程序,统计文本stdin中字符$出现的次数,并将结果写入文件stdout 输入 字符文本 输出 $次数 样例输入 as$dfkjhkjkjdhf asdfkj$lskdfj werijw ...

  3. 使用Wisdom RESTClient进行自动化测试,如何取消对返回的body内容的校验?对排除的JSON属性字段不做校验?

    使用 Wisdom RESTClient 进行自动化测试 REST API,默认是对返回HTTP状态码和body内容都进行严格匹配和校验. (1). 如果每次触发API返回的body内容是动态变化的, ...

  4. 基于Theano的深度学习框架keras及配合SVM训练模型

    https://blog.csdn.net/a819825294/article/details/51334397 1.介绍 Keras是基于Theano的一个深度学习框架,它的设计参考了Torch, ...

  5. Java连接数据库 #01# JDBC单线程适用

    官方教程(包括 javase的基础部分):JDBC Basics 重新梳理.学习一下“Java连接数据库”相关的内容. 因为最开始没有认真学多线程和JDBC,一直在自己写的多线程程序中维持下面的错误写 ...

  6. if语法

    语法一: if 条件:   条件成立时执行的子代码块 age_of_girl=31 if age_of_girl > 30: print('阿姨好') 语法二:if + else   if 条件 ...

  7. mycat高可用集群搭建

    本文来源于:https://blog.csdn.net/u012758088/article/details/78741567 Mycat 本身是无状态的,可以用 HAProxy 或四层交换机等设备组 ...

  8. PHP API接口签名验证

    hash_hmac 在php中hash_hmac函数就能将HMAC和一部分哈希加密算法相结合起来实现HMAC-SHA1  HMAC-SHA256 HMAC-MD5等等算法.函数介绍如下: string ...

  9. TNS-12537,TNS-12560,TNS-00507 Linux Error: 29: Illegal seek解决

    下午有个测试环境测试人员反馈oracle监听起不来,一启动就报错,还生成了core文件.如下: [oracle@localhost ~]$ lsnrctl start LSNRCTL for Linu ...

  10. 实现 AD 采样,使用 LCD1602 显示 AD 数值

    实现 AD 采样,使用 LCD1602 显示 AD 数值 写在前面 单片机内集成的A/D转换,一般都有相应的特殊功能寄存器来设置A/D的使能标志,参考电压,转换频率,通道选择,A/D输入口的属性(模拟 ...