You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Gdsi-Api/Gdsi/Helper/Http.cs

111 lines
3.1 KiB

using Gdsi.Config;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Gdsi.Helper
{
public class Http
{
private static string smethod_0(string string_0)
{
byte[] bytes = Encoding.UTF8.GetBytes(string_0);
byte[] array = SHA256.Create().ComputeHash(bytes);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < array.Length; i++)
{
stringBuilder.Append(array[i].ToString("x2"));
}
return stringBuilder.ToString();
}
private static string smethod_1()
{
return Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds).ToString();
}
private static string smethod_2(int int_0, bool bool_0, bool bool_1, bool bool_2, bool bool_3, string string_0 = "")
{
byte[] array = new byte[4];
new RNGCryptoServiceProvider().GetBytes(array);
Random random = new Random(BitConverter.ToInt32(array, 0));
string text = null;
string text2 = string_0;
if (bool_0)
{
text2 += "0123456789";
}
if (bool_1)
{
text2 += "abcdefghijklmnopqrstuvwxyz";
}
if (bool_2)
{
text2 += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
if (bool_3)
{
text2 += "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
}
for (int i = 0; i < int_0; i++)
{
text += text2.Substring(random.Next(0, text2.Length - 1), 1);
}
return text;
}
public static string HttpPostByHeader(string url, string param, Dictionary<string, string> dicHeader = null)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/json;charset=UTF-8";
if (dicHeader == null)
{
dicHeader = new Dictionary<string, string>();
string text = smethod_1();
string text2 = smethod_2(32, bool_0: true, bool_1: true, bool_2: false, bool_3: false);
string value = GdsiConfig.paasid;
string text3 = GdsiConfig.key;
string value2 = smethod_0(text + text3 + text2 + text);
dicHeader.Add("x-tif-paasid", value);
dicHeader.Add("x-tif-signature", value2);
dicHeader.Add("x-tif-timestamp", text);
dicHeader.Add("x-tif-nonce", text2);
}
if (dicHeader != null && dicHeader.Count != 0)
{
foreach (KeyValuePair<string, string> item in dicHeader)
{
httpWebRequest.Headers.Add(item.Key, item.Value);
}
}
byte[] bytes = Encoding.UTF8.GetBytes(param);
httpWebRequest.ContentLength = bytes.Length;
string text4 = "";
try
{
Stream requestStream = httpWebRequest.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream responseStream = httpWebResponse.GetResponseStream();
string text5 = "";
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
while ((text5 = streamReader.ReadLine()) != null)
{
text4 += text5;
}
return text4;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}