发送数据流方法

/// <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. TensorFlow入门,基本介绍,基本概念,计算图,pip安装,helloworld示例,实现简单的神经网络

    TensorFlow入门,基本介绍,基本概念,计算图,pip安装,helloworld示例,实现简单的神经网络

  2. I2S接口介绍

    I2S接口介绍一.I2S协议介绍 I2S协议作为音频数据传输协议,由Philips制定.该协议由三条数据线组成:1.SCLK:串行时钟,频率= 2 * 采样频率 * 采样位数.2.WS:字段(声道)选 ...

  3. [转载] 关于出现“使用 UNION、INTERSECT 或 EXCEPT 运算符合并的所有查询必须在其目标列表中有相同数目的表达式”错误的可能原因

    1. 对于该问题确实存在UNION前后SELECT语句中的列数不同导致:2. 以下为个人遇到的一种可能:在项目开发中由于有张表是动态的,即有个基础表,其他的表按年月根据基础表来生成动态表,动态表结构和 ...

  4. game to refactor for refactor

    first step, only aim to work. it works, but i have not seen the necessaty to use class yet. my quest ...

  5. lnmp vhost 文件

    server { listen 80 default_server; #listen [::]:80 default_server ipv6only=on; server_name blog.yang ...

  6. appJar 界面效果

    appJar from appJar import gui app = gui() def main(): app.setLocation(200, 200) app.addLabel('2333', ...

  7. flask模板,路由,消息提示,异常处理

    1.flask的路由与反向路由 from flask import Flask, request, url_for app = Flask(__name__) @app.route('/') def ...

  8. Linux LAMP架构搭建

    一.部署LAMP基本架构 1.L(linux)A(apache)M(mysql)P(php) 2.稳定版本(mysql5.1,php5.3,apache2.2) 3.安装顺序,mysql-->a ...

  9. RadioButton在数据列表中实现单选功能

    在服务器端动态生成的name总是不断变化,故需手动实现单选 ; <html xmlns="http://www.w3.org/1999/xhtml"> <head ...

  10. topcoder srm 505 div1

    problem1 link 设行数为$n$列数为$m$ 对于任意的两行$r_{1},r_{2}$以及任意的两列$c_{1},c_{2}$所确定的四个格子,只要知道其中的三个就能确定第四个,且必须要三个 ...