12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using Microsoft.AspNetCore.Http;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using System.Net;
- using Newtonsoft.Json.Linq;
- using Newtonsoft.Json;
- using System.Net.Http;
- namespace DllMsgPackage
- {
- public class HttpHelp
- {
- public static DataSet GetDataSetFromHttpRequest(HttpRequest request, ref string errorinfo)
- {
- try
- {
- long len = (long)request.ContentLength;
- byte[] datas = new byte[len];
- long lev = len;
- while (lev > 0)
- {
- byte[] buffers = null;
- int max = 0;
- if (lev <= 1024)
- {
- buffers = new byte[lev];
- max = (int)lev;
- }
- else
- {
- buffers = new byte[1024];
- max = 1024;
- }
- int readlen = request.Body.Read(buffers, 0, max);
- if (readlen > 0)
- {
- Array.Copy(buffers, 0, datas, len - lev, readlen);
- }
- lev = lev - readlen;
- }
- string jsonstr = System.Text.Encoding.Default.GetString(datas);
- DataSet reds = MsgPackage.StrToDataSet(jsonstr, ref errorinfo);
- return reds;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- }
- public static string GetJsonStrFromHttpRequest(HttpRequest request, ref string errorinfo)
- {
- try
- {
- long len = (long)request.ContentLength;
- byte[] datas = new byte[len];
- long lev = len;
- while (lev > 0)
- {
- byte[] buffers = null;
- int max = 0;
- if (lev <= 1024)
- {
- buffers = new byte[lev];
- max = (int)lev;
- }
- else
- {
- buffers = new byte[1024];
- max = 1024;
- }
- int readlen = request.Body.Read(buffers, 0, max);
- if (readlen > 0)
- {
- Array.Copy(buffers, 0, datas, len - lev, readlen);
- }
- lev = lev - readlen;
- }
- string jsonstr = System.Text.Encoding.Default.GetString(datas);
- return jsonstr;
- }
- catch (Exception ex)
- {
- errorinfo = ex.Message.ToString();
- return null;
- }
- }
- }
- }
|