C#.NET WebApi返回各种类型(图片/json数据/字符串),.net图片转二进制流或byte
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json

·
原文:http://www.itdos.com/Mvc/20150302/0741255.html
using System.IO; /// <summary> /// WebApi返回图片 /// </summary> public HttpResponseMessage GetQrCode() { var imgPath = @"D:\ITdosCom\Images\itdos.jpg"; //从图片中读取byte var imgByte = File.ReadAllBytes(imgPath); //从图片中读取流 var imgStream = new MemoryStream(File.ReadAllBytes(imgPath)); var resp = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(imgByte) //或者 //Content = new StreamContent(stream) }; resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); return resp; } /// <summary> /// WebApi返回json数据 /// </summary> public HttpResponseMessage GetQrCode() { var jsonStr = "{\"IsSuccess\":true,\"Data\":\"www.itdos.com\"}"; var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(jsonStr, Encoding.UTF8, "text/json") }; return result; } /// <summary> /// WebApi返回字符串 /// </summary> public HttpResponseMessage GetQrCode() { var str = "IT大师www.itdos.com"; var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(str, Encoding.UTF8, "text/plain") }; return result; }




适用于现代 C++ 的 JSON。
最近提交(Master分支:5 个月前 )
34665ae6
binary -> binary_t
Signed-off-by: Robert Chisholm <robert.chisholm@sheffield.ac.uk> 6 天前
f3dc4684
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.9 to 3.28.10.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0...b56ba49b26e50535fa1e7f7db0f4f7b4bf65d80d)
---
updated-dependencies:
- dependency-name: github/codeql-action
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 13 天前
更多推荐
所有评论(0)