MVC 返回404,返回图片,流到数组,apk信息

时间:2022-01-15 02:08:07
                return HttpNotFound();
            byte[] buffer0 = QRCode();
return File(buffer0, @"image/jpeg"); // //通过二进制数据的方式 直接返回图片,在线浏览
  Image ss = CreateImage("",false,);
MemoryStream ms = new MemoryStream();
ss.Save(ms, ImageFormat.Jpeg);
byte[] buffer = new byte[ms.Length];
ms.Read(buffer, , buffer.Length);
return File(ms.ToArray(), @"image/jpeg"); // //通过二进制数据的方式
//暂无测试
FileStream fs = new FileStream(); MemoryStream ms = new MemoryStream();
img0.Save(ms, ImageFormat.Jpeg);
byte[] buffer = new byte[ms.Length];
ms.Read(buffer, , buffer.Length); //读取数据到字节数组
fs.Read(buffer, , buffer.Length); //读取字节数组到缓冲区
return new FileStreamResult(new FileStream(path, FileMode.Open), "image/jpeg");

//文件的输入流

                Stream filestrem =  file.InputStream;
StreamReader sr = new StreamReader(filestrem, System.Text.Encoding.GetEncoding("gb2312"));
string stringReader = sr.ReadToEnd();
            StreamReader sr = new StreamReader(filestrem, System.Text.Encoding.GetEncoding("gb2312"));
string stringReader = sr.ReadToEnd(); //流转字符串
sr.BaseStream.Seek(, SeekOrigin.Begin); //重置流 sr.Close();sr.Dispose(); //读取完后,关闭流
MemoryStream ms = new MemoryStream(System.Text.Encoding.Default.GetBytes(stringReader));
return ms;
// (1)byte[] bt=ms.ToArray();
//(2)MemoryStream ms=new MemoryStream();ms.Write(bt,0,ms.Length);
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace WindowsForm_CheckApk
{ public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Cmd c = new Cmd(); string.Format("{0} d badging {1}", "aapt.exe的path", "apk的path"); var str = c.RunCmd(@"E:\迅雷下载\小米5线刷\ext4_unpacker\ext4_unpacker\aapt.exe d badging C:\14.apk"); //byte[] UTF8byte = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, byteArray); List<Encoding> encodings = new List<Encoding>();
encodings.Add(System.Text.Encoding.Unicode);
encodings.Add(System.Text.Encoding.ASCII);
encodings.Add(System.Text.Encoding.Default);
encodings.Add(System.Text.Encoding.GetEncoding("GB2312")); //||GetEncoding("gbk") 都是GB2132
encodings.Add(System.Text.Encoding.GetEncoding("big5")); //繁体中文
encodings.Add(System.Text.Encoding.UTF7);
encodings.Add(System.Text.Encoding.UTF8);
encodings.Add(System.Text.Encoding.GetEncoding("GB18030")); List<byte[]> bytes = new List<byte[]>();
for (int i = ; i < encodings.Count; i++)
{
bytes.Add(encodings[i].GetBytes(str)); //以指定编码读取字符串到数组
} //Unicode 转 UTF8
byte[] UTF8byte = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, bytes[]);
//将UTF8编码byte[]变为UTF8编码的字符串,编码一致,肯定可正确显示
string str1 = Encoding.UTF8.GetString(UTF8byte); List<string> outstrs = new List<string>(); //输出的字符串 for (int i = ; i < bytes.Count; i++)
{
outstrs.Add(Encoding.UTF8.GetString(bytes[i], , bytes[i].Length)); //
} //使用GetString方法,得到的string都是unicode编码的
var gb = System.Text.Encoding.Default.GetBytes(str); //使用ASCII读取和Unicode读取,都乱码 , 使用UTF8读取也乱码,,使用ANSI读取,使用UTF8解码
var gb2132_str = System.Text.Encoding.GetEncoding("GB2312").GetString(gb);
var utf8_str = System.Text.Encoding.UTF8.GetString(gb);
var ascii_str = System.Text.Encoding.ASCII.GetString(gb);
var default_str = System.Text.Encoding.Default.GetString(gb);
var ansi_str = System.Text.Encoding.UTF7.GetString(gb); var td = ""; //byte[] byteArray = System.Text.Encoding.Default.GetBytes("00"); //以默认编码读取字符串到 字节数组
//string aaa2 = System.Text.Encoding.Default.GetString(byteArray); //以默认编码 获得字节数组, 到字符串 }
/// <summary>
/// 字符串转为UniCode码字符串
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string StringToUnicode(string s)
{
char[] charbuffers = s.ToCharArray();
byte[] buffer;
StringBuilder sb = new StringBuilder();
for (int i = ; i < charbuffers.Length; i++)
{
buffer = System.Text.Encoding.Unicode.GetBytes(charbuffers[i].ToString());
sb.Append(String.Format("\\u{0:X2}{1:X2}", buffer[], buffer[]));
}
return sb.ToString();
} /// 字符串转Unicode
/// </summary>
/// <param name="source">源字符串</param>
/// <returns>Unicode编码后的字符串</returns>
public static string String2Unicode(string source)
{
var bytes = Encoding.Unicode.GetBytes(source);
var stringBuilder = new StringBuilder();
for (var i = ; i < bytes.Length; i += )
{
stringBuilder.AppendFormat("\\u{0:x2}{1:x2}", bytes[i + ], bytes[i]);
}
return stringBuilder.ToString();
} //编码测试
private void button2_Click(object sender, EventArgs e)
{
string u16s = "忘記了啊abc"; //默认的字符编码是unicode,也就是utf16 //4种编码
Encoding utf8 = Encoding.UTF8;
Encoding utf16 = Encoding.Unicode;
Encoding gb = Encoding.GetEncoding("gbk");
Encoding b5 = Encoding.GetEncoding("big5"); //转换得到4种编码的字节流
byte[] u16bytes = utf16.GetBytes(u16s);
byte[] u8bytes = Encoding.Convert(utf16, utf8, u16bytes);
byte[] gbytes = Encoding.Convert(utf16, gb, u16bytes);
byte[] bbytes = Encoding.Convert(utf16, b5, u16bytes); // unicode
List<string> unicode_list = new List<string>();
unicode_list.Add("unicode: ");
foreach (byte c in u16bytes)
{
unicode_list.Add(((int)c).ToString("x") + " ");
} // UTF-8
List<string> utf8_list = new List<string>();
utf8_list.Add("utf8: ");
foreach (byte c in u8bytes)
{
utf8_list.Add(((int)c).ToString("x") + " ");
} // GBK
List<string> gbk_list = new List<string>();
gbk_list.Add("gbk: ");
foreach (byte c in gbytes)
{
gbk_list.Add(((int)c).ToString("x") + " ");
} // big5
List<string> big5_list = new List<string>();
big5_list.Add("big5: ");
foreach (byte c in bbytes)
{
big5_list.Add(((int)c).ToString("x") + " ");
} //得到4种编码的string
string u8s = utf8.GetString(u8bytes);
string gs = gb.GetString(gbytes);
string bs = b5.GetString(bbytes); Console.WriteLine("unicode: " + u16s + " " + u16s.Length.ToString());
Console.WriteLine("utf8: " + u8s + " " + u16s.Length.ToString());
Console.WriteLine("gbk: " + gs + " " + gs.Length.ToString());
Console.WriteLine("big5: " + bs + " " + bs.Length.ToString()); Console.Write("unicode: ");
foreach (char c in u16s)
{
Console.Write(((int)c).ToString("x") + " ");
}
Console.WriteLine(); Console.Write("utf8: ");
foreach (char c in u8s)
{
Console.Write(((int)c).ToString("x") + " ");
}
Console.WriteLine(); Console.Write("gb2312: ");
foreach (char c in gs)
{
Console.Write(((int)c).ToString("x") + " ");
}
Console.WriteLine(); Console.Write("big5: ");
foreach (char c in bs)
{
Console.Write(((int)c).ToString("x") + " ");
}
Console.WriteLine(); }
}
/// <summary>
/// Cmd 的摘要说明。
/// </summary>
public class Cmd: Process
{
private Process proc = null;
/// <summary>
/// 构造方法
/// </summary>
public Cmd()
{
proc = new Process();
} /// <summary>
/// 执行CMD语句
/// </summary>
/// <param name="cmd">要执行的CMD命令</param>
public string RunCmd(string cmd)
{
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
proc.StandardInput.WriteLine(cmd);
proc.StandardInput.WriteLine("exit");
#region --测试代码 //System.IO.Stream t = proc.StandardOutput.BaseStream;
//byte[] bytes = new byte[t.Length]; //报错 流不支持查找
//t.Read(bytes, 0, bytes.Length);
//var out_str = System.Text.Encoding.UTF8.GetString(bytes);
//// (1)byte[] bt=ms.ToArray();
////(2)MemoryStream ms=new MemoryStream();ms.Write(bt,0,ms.Length); System.IO.StreamReader sOut = proc.StandardOutput;//这里是获取到一个StreamReader 流 byte[] bytes;
using (MemoryStream memstream = new MemoryStream())
{
int bytesRead = ;
byte[] buffer = new byte[];
while ((bytesRead = sOut.BaseStream.Read(buffer, , buffer.Length)) > )
{
memstream.Write(buffer, , bytesRead);
}
bytes = memstream.ToArray(); //FileStream keyfs = new FileStream(Server.MapPath("/key/regkey2.dat"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write);
//BinaryWriter w = null;
//w = new BinaryWriter(keyfs);
//for (int t = 0; t < bytes.Length; t++)
//{
// w.Write((byte)bytes[t]);
//} memstream.Close();
//w.Close();
//keyfs.Close(); } // t..CopyTo(ms);
//var ms = StreamToMemoryStream(t); var out_str = System.Text.Encoding.Default.GetString(bytes); #endregion #region --原始代码
string outStr = proc.StandardOutput.ReadToEnd(); proc.Close();
return outStr;
#endregion
}
System.IO.MemoryStream StreamToMemoryStream(System.IO.Stream instream)
{
System.IO.MemoryStream outstream = new System.IO.MemoryStream();
const int bufferLen = ;
byte[] buffer = new byte[bufferLen];
int count = ;
while ((count = instream.Read(buffer, , bufferLen)) > )
{
outstream.Write(buffer, , count);
}
return outstream;
}
/// <summary>
/// 打开软件并执行命令
/// </summary>
/// <param name="programName">软件路径加名称(.exe文件)</param>
/// <param name="cmd">要执行的命令</param>
public void RunProgram(string programName, string cmd)
{
Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = programName;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
if (cmd.Length != )
{
proc.StandardInput.WriteLine(cmd);
}
proc.Close();
}
/// <summary>
/// 打开软件
/// </summary>
/// <param name="programName">软件路径加名称(.exe文件)</param>
public void RunProgram(string programName)
{
this.RunProgram(programName, "");
}
}
先把流转换为字节数组
System.IO.StreamReader sOut = proc.StandardOutput;//这里是获取到一个StreamReader流
using (MemoryStream memstream = new MemoryStream())
{
int bytesRead = ;
byte[] buffer = new byte[];
while ((bytesRead = sOut.BaseStream.Read(buffer, , buffer.Length)) > )
{
memstream.Write(buffer, , bytesRead);
}
bytes = memstream.ToArray();
memstream.Close();
}
再把字节数组以指定编码转为字符串
var out_str = System.Text.Encoding.UTF8.GetString(bytes);

MVC 返回404,返回图片,流到数组,apk信息的更多相关文章

  1. 【转载】C&num;&period;NET WebApi返回各种类型&lpar;图片&sol;json数据&sol;字符串&rpar;,&period;net图片转二进制流或byte

    C#.NET WebApi返回各种类型(图片/json数据/字符串),.net图片转二进制流或byte 转载:http://www.itdos.com/Mvc/20150302/0741255.htm ...

  2. ASP&period;NET误人子弟教程:在MVC下如何返回图片

    这几天忙着一些小事,也没有写什么了,今天,我们来玩一个比较简单的东东.就是在MVC下如何返回图片,相信,在传统WebForm下,大家都晓得怎么弄,方也不限于一种,但是,在架构较为严格的MVC里面,刚开 ...

  3. vue中图片返回404时,显示默认的图片

    图片返回404时候的处理 <img :src="userMsg.portrait" ref="img" alt=""> _thi ...

  4. ASP&period;NET MVC请求特殊静态文件返回404 Not Found

    今天在请求静态的json档案以及woff2档案,会返回404错误,需要在Web.Config里修改: <system.webServer> <modules> <remo ...

  5. mvc项目 ajax post 返回404错误

    后台代码没有问题,但是一直出现404错误 原因:iis设置,请求中文件大小超过限制会被过滤掉,直接返回404. 解决:设置iis,应用程序->请求筛选->规则->编辑功能设置-&gt ...

  6. ASP&period;NET MVC – 关于Action返回结果类型的事儿(上)

    原文:ASP.NET MVC – 关于Action返回结果类型的事儿(上) 本文转自:博客园-文超的技术博客 一.         ASP.NET MVC 1.0 Result 几何? Action的 ...

  7. &period;Net之使用Jquery Ajax通过FormData对象异步提交图片文件到服务端保存并返回保存的图片路径

    前言: 首先对于图片上传而言,在我们的项目开发中可以说出现的频率是相当的高的.这篇文章中,我将要描述的是在我们.Net中如何使用Jquery Ajax通过FormData对象异步提交图片文件到后台保存 ...

  8. mvc使用JsonResult返回Json数据

    mvc使用JsonResult返回Json数据   controller 中定义以下方法: public JsonResult UpdateSingle(int id, string actionNa ...

  9. springmvc 返回 404 解决

    Idea Maven springmvc spring 项目搭建中/url 可以访问controller,并且能返回正确的ModelAndView,但是页面总是显示404 项目结构: web.xml ...

随机推荐

  1. JDBC的简单使用

    JDBC的英文全称是:  java Data Base Connectivity JDBC的主要作用:  (是java数据库连接技术的简称)JDBC是由一系列连接(Conneation).SQL语句( ...

  2. Python 学习---------Day5

    第十四章 文档 class employee: "class doumentation" pass print employee.__doc__ #注释会保存在__doc__属性中 ...

  3. DropDownList中显示无限级树形结构

    效果图: 数据库表: DirID:目录的ID,ParentID:目录的父路径ID,Name:目录的名字主要代码: using System;using System.Collections;using ...

  4. python 学习笔记2(list/directory/文件对象/模块/参数传递)

    ### Python的强大很大一部分原因在于,它提供有很多已经写好的,可以现成用的对象. 11. list list是一个类.每个列表都属于该类. >>>nl = [1,2,5,3, ...

  5. Android各个版本 版本号对应关系表

    Platform Version API Level VERSION_CODE Notes Android 5.0 21 LOLLIPOP Platform Highlights Android 4. ...

  6. 隐藏 response headers

    1.response headers 为何物 从上图看到..这 透漏出服务器端 1.操作系统版本, IIS版本.开发语言 .以及.net framework 版本 虽然现在IIS 可以挂php .甚至 ...

  7. navicat导入mysql数据库sql时报错或数据不完全问题

    错误详情:[Err] [Imp] 2006 - MySQL server has gone away 或无提示错误,但是导入数据明显缺少字段和数据 找到服务器上的MYSQL安装目录下的my.ini文件 ...

  8. FineUI初学手册

    女朋友鄙视我原创少... 1.下载 进入官方论坛:http://www.fineui.com/bbs/ 要用到下载源代码和空项目下载 http://fineui.codeplex.com/ http: ...

  9. ubuntu tips

    1.ibus-setup 2.tips:

  10. maven与eclipse连接的配置

    1.修改本地仓库位置 maven从中心仓库下载的文件一般默认放在本地用户文件加下的.m2/repository文件夹中,修改则需要找到所下载的maven文件夹下的conf文件夹下的setting.xm ...