//流请求

static void Main(string[] args)

{
Console.WriteLine("Hello World!");
//Console.ReadLine();
List<EB_LOG> logs=new List<EB_LOG>(){
new EB_LOG (){ id="11111", name="22222"},
new EB_LOG (){ id="11111", name="22222"},
};
MemoryStream fs = ToExcel<EB_LOG>(logs);
using (var httpClient = new HttpClient())
{
//1.创建文件流
//FileStream fsRead = new FileStream(@"C:\Users\AmyZeng\Desktop\1.txt", FileMode.Open);
//2.创建缓冲区,正常情况下,是不会直接等于文件大小的。这里只有读,所以就这么干了。
byte[] byteArray = fs.ToArray();
fs.Read(byteArray, 0, byteArray.Length);
//3.开始读取, 返回值是读取到的长度。
//int r = fsRead.Read(bytes, 0, bytes.Lenght);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://localhost:58278接收地址"));
webRequest.Method = "POST"; //POST
webRequest.ContentType = "application/x-xls";
webRequest.ContentLength = byteArray.Length;
Stream newStream = webRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string sss = sr.ReadToEnd();
//4.关闭释放流
fs.Close();
fs.Dispose();
}
 
}
public static MemoryStream ToExcel<T>(List<T> list, string filePath = null)
{
var memoryStream = new MemoryStream();
 
IWorkbook workbook = new HSSFWorkbook();
string sheetName = typeof(T).Name;
ISheet sheet = workbook.CreateSheet(sheetName);
IRow headerRow = sheet.CreateRow(0);
Type elementType = typeof(T);
// handling header.
int headerIndex = 0;
elementType.GetProperties().ToList().ForEach(propInfo =>
{
ICell headerCell = headerRow.CreateCell(headerIndex);
headerIndex = headerIndex + 1;
headerCell.SetCellValue(propInfo.Name);
});
int rowIndex = 1;
foreach (T item in list)
{
IRow dataRow = sheet.CreateRow(rowIndex);
int rowcellIndex = 0;
elementType.GetProperties().ToList().ForEach(propInfo =>
{
ICell cell = dataRow.CreateCell(rowcellIndex);
string value = (propInfo.GetValue(item, null) ?? "").ToString();
cell.SetCellValue(value);
rowcellIndex++;
});
rowIndex++;
}
///storage/emulated/0/DCIM
//FileStream fs = new FileStream("/storage/emulated/0/DCIM/log.xls", FileMode.OpenOrCreate, FileAccess.ReadWrite);
workbook.Write(memoryStream);
//fs.Write(memoryStream.ToArray(), 0, (int)memoryStream.Length);
 
//fs.Dispose();
workbook = null;
return memoryStream;
 }
 
 
 
//接收代码

string logpatch = “D:\Logs\”
if (!string.IsNullOrEmpty(logpatch))
{
if (!System.IO.Directory.Exists(logpatch))
{
System.IO.Directory.CreateDirectory(logpatch);
}
}
else
{

logpatch = System.AppDomain.CurrentDomain.BaseDirectory+ "Logs\\";
if (!System.IO.Directory.Exists(logpatch))
{
System.IO.Directory.CreateDirectory(logpatch);
}
}

logpatch = logpatch + System.DateTime.Today.ToString("yyyyMMdd") + "\\";
if (!System.IO.Directory.Exists(logpatch))
{
System.IO.Directory.CreateDirectory(logpatch);
}

byte[] bufferSteam = new byte[context.Request.InputStream.Length];
context.Request.InputStream.Read(bufferSteam, 0, bufferSteam.Length);
string strPath = logpatch + DateTime.Now.ToString("yyyyMMddHHmmsss")+"_" + strStoreTillid + ".xls";
FileStream fsSteam = new FileStream(strPath, FileMode.Create, FileAccess.Write);
BinaryWriter bwSteam = new BinaryWriter(fsSteam);
bwSteam.Write(bufferSteam);
bwSteam.Close();
fsSteam.Close();

 
 

MemoryStream请求与接收的更多相关文章

  1. Android HTTP实例 发送请求和接收响应

    Android HTTP实例 发送请求和接收响应 Android Http连接 实例:发送请求和接收响应 添加权限 首先要在manifest中加上访问网络的权限: <manifest ... & ...

  2. struts2之请求参数接收

    struts2之请求参数接收 1. 采用基本类型接受请求参数(get/post)在Action类中定义与请求参数同名的属性,struts2便能自动接收请求参数并赋予给同名的属性.请求路径:http:/ ...

  3. 使用HttpClient发送请求、接收响应

    使用HttpClient发送请求.接收响应很简单,只要如下几步即可. 1.创建HttpClient对象.  CloseableHttpClient httpclient = HttpClients.c ...

  4. Struts2 请求参数接收

    在Struts2中提供了更为简单的参数请求与接收方法,可以直接在Action中定义属性:Struts2通过反射机制将参数反射到属性的set方法上实现参数的传递: GET方式传送参数 <strut ...

  5. JAVA发送HttpClient请求及接收请求结果

    1.写一个HttpRequestUtils工具类,包括post请求和get请求 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 ...

  6. python通过get,post方式发送http请求和接收http响应的方法,pythonget

    python通过get,post方式发送http请求和接收http响应的方法,pythonget 本文实例讲述了python通过get,post方式发送http请求和接收http响应的方法.分享给大家 ...

  7. python通过get方式,post方式发送http请求和接收http响应-urllib urllib2

    python通过get方式,post方式发送http请求和接收http响应-- import urllib模块,urllib2模块, httplib模块 http://blog.163.com/xyc ...

  8. javascript实现select菜单/级联菜单(用Rails.ajax实现发送请求,接收响应)

    在购物网站,填写收货地址的时候,会出现XX省XX市XX区的下拉菜单,如何实现此功能?思路是什么? 功能设置: 当选择省select菜单后,市的select菜单为这个省的城市列. 当选择市菜单后,区菜单 ...

  9. SpringMVC请求参数接收总结

    前提 在日常使用SpringMVC进行开发的时候,有可能遇到前端各种类型的请求参数,这里做一次相对全面的总结.SpringMVC中处理控制器参数的接口是HandlerMethodArgumentRes ...

随机推荐

  1. js canvas游戏初级demo-上下左右移动

    大概流程就是监听状态变化擦除画布重绘 由于js监听时间变化的函数addEventListener只能达到每秒触发20次左右,也就是每秒20帧,看起来有点卡卡的 所以用定时器搞到每秒30帧 按上下左右键 ...

  2. [git] git怎样fork一个repo

    描述 我定制了一下strongswan的工程.然后想把我自己的定制变成一个repo push到远端git.tong.com与大家分享. 这个时候,应该怎么做? 如果你用过github的话.那么你可以理 ...

  3. Python_tkinter(4)_上传文件

    1.上传单个文件 import tkinter as tk from tkinter import filedialog def upload_file(): selectFile = tk.file ...

  4. Python 中文分词(结巴分词)

    特点: 支持三种分词模式: 精确模式,试图将句子最精确地切开,适合文本分析: 全模式,把句子中所有的可以成词的词语都扫描出来, 速度非常快,但是不能解决歧义: 搜索引擎模式,在精确模式的基础上,对长词 ...

  5. 用vue怎么写点击保存之后的返回的代码?

    点击完保存调用接口之后,如果使用  this.$router.go(-1); 返回到编辑页面,数据不会有更新,使用 this.$router.replace({ name: '信息展示', param ...

  6. 获取UILabel的numberOfLine

    获取UILabel的numberOfLine CGFloat textH = [self.label.text boundingRectWithSize:CGSizeMake(width, MAXFL ...

  7. HDD ,SSD和PCIE SSD性能测试

      PCIE SSD   * MB/s = 1,000,000 bytes/s [SATA/600 = 600,000,000 bytes/s] * KB = 1000 bytes, KiB = 10 ...

  8. django集成ansibe实现自动化

    动态生成主机列表和相关参数 def create_admin_domain(admin_node): workpath = BASE_DIR + '/tools/ansible/script' hos ...

  9. raise error

    raise TypeError("参数q_type 错误 ")

  10. 字符串只截取小数后n位,不做四舍五入

    例子1: var num = "112233.99887766";console.log(num.substring(0,(num.indexOf(".")+5 ...