老师,有以下C#格式API接口代码如何转为FT格式?能否麻烦老师帮忙转换一下,万分谢谢!
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
public class Test{
public const String appId = "数脉分配给你的appid";
public const String appSecurity = "数脉分配给你的appsecurity";
public static string GetMD5(string myString) {
MD5 md5 = new MD5CryptoServiceProvider();
byte[] fromData = System.Text.Encoding.UTF8.GetBytes(myString);
byte[] targetData = md5.ComputeHash(fromData);
string byte2String = null;
for (int i = 0; i < targetData.Length; i++) {
byte2String = byte2String+ targetData[i].ToString("x2");
}
return byte2String;
}
public static void Main(string[] args) {
long t = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds);
String str = appId + "&" + t + "&" + appSecurity;
String sign = GetMD5(str);
String keyword = "关键字,公司名全称、注册号、社会统一信用代码";
HttpWebRequest httpRequest = null;
HttpWebResponse httpResponse = null;
String url = "https://api.shumaidata.com/v4/business4/get?appid="+appId+"×tamp="+t+"&sign="+sign+"&keyword="+keyword;
if (url.Contains("https://")) {
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url));
} else {
httpRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpRequest.Method = "GET";
try {
httpResponse = (HttpWebResponse)httpRequest.GetResponse();
} catch (WebException ex) {
httpResponse = (HttpWebResponse)ex.Response;
}
Console.WriteLine(httpResponse.StatusCode);
Console.WriteLine(httpResponse.Method);
Console.WriteLine(httpResponse.Headers);
Stream st = httpResponse.GetResponseStream();
StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8"));
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("\n");
}
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
}
[此贴子已经被作者于2024/3/3 18:24:26编辑过]