请问老师下面c#转出foxtable 要怎么写?
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Text;
namespace MyDemo
{
class Program
{
public static string HttpGet(string url, string contentType)
{
if (url.StartsWith("https"))
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
}
HttpClient httpClient = new HttpClient();
if (!string.IsNullOrWhiteSpace(contentType))
{
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue(contentType));
}
HttpResponseMessage response = httpClient.GetAsync(url).Result;
string result = response.Content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
return result;
}
else
{
throw new Exception(result);
}
}
public static string HttpPost(String url, string body, string contentType)
{
HttpWebResponse httpWebResponse = null;
try
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = contentType;
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";
httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
httpWebRequest.CookieContainer = new CookieContainer();
byte[] btBodys = Encoding.UTF8.GetBytes(body);
httpWebRequest.ContentLength = btBodys.Length;
httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
string responseContent = streamReader.ReadToEnd();
httpWebResponse.Close();
streamReader.Close();
httpWebResponse.Close();
httpWebRequest.Abort();
return responseContent;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (httpWebResponse != null)
{
httpWebResponse.Close();
}
}
}
public static string Md5(string strInput)
{
byte[] result = Encoding.Default.GetBytes(strInput.Trim());
//tbPass为输入密码的文本框
MD5 md5 = new MD5CryptoServiceProvider();
byte[] output = md5.ComputeHash(result);
return BitConverter.ToString(output).Replace("-", "");
}
/// <summary>
/// 构造访问的url
/// </summary>
/// <param name="paramsMap">参数列表</param>
/// <param name="isSign">是否构造签名串</param>
/// <returns></returns>
private static string GetRequestQueryString(Dictionary<string, string> paramsMap, bool isSign)
{
StringBuilder sb = new StringBuilder();
List<string> list = paramsMap.Keys.ToList();
if (isSign)
{
list.Sort(); //排序参数
}
foreach (string key1 in list)
{
sb.Append("&");
sb.Append(key1);
sb.Append("=");
if (isSign)
{
sb.Append(paramsMap[key1]);
}
else
{
sb.Append(Uri.EscapeDataString(paramsMap[key1]));
}
}
return sb.ToString().Substring(1);
}
private static string InvokeOpenApi(HttpMethod httpMethod,
string openUrl,
string userId,
string key,
string method,
string format,
string version,
Dictionary<string, string> param)
{
Dictionary<string, string> paramsMap = new Dictionary<string, string>();
String timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
paramsMap.Add("user_id", userId);
paramsMap.Add("format", format);
paramsMap.Add("timestamp", timestamp);
paramsMap.Add("method", method);
if (version.Equals("2.0"))
{
paramsMap.Add("version", version); //2.0版本增加version参数
}
foreach (string paramkey in param.Keys)
{
paramsMap.Add(paramkey, param[paramkey]); //将外部参数也加入到列表中
}
if (version.Equals("2.0"))
{
string urlString = GetRequestQueryString(paramsMap, true);
urlString = urlString + "&key=" + key;
string sign = Md5(urlString).ToUpper();
paramsMap.Add("sign", sign);
}
else if (version.Equals("1.0"))
{
string sign = Md5(userId + key + timestamp).ToUpper();
paramsMap.Add("sign", sign);
}
string result = "";
string invokeUrl = GetRequestQueryString(paramsMap, false);
if (httpMethod == HttpMethod.Get)
{
result = HttpGet(openUrl + "?" + invokeUrl, "application/json");
}
else if (httpMethod == HttpMethod.Post)
{
result = HttpPost(openUrl, invokeUrl, "application/x-www-form-urlencoded");
}
else
{
throw new Exception("invokeOpenApi 2.0 not support httpmethod" + httpMethod.ToString());
}
return result;
}
static void Main(string[] args)
{
string releaseApiUrl = "http://api.nbeport.com/router/rest";
string debugApiUrl = "http://api.trainer.nbeport.com/router/rest";
string userId = "xxxxx";
string key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
Dictionary<String, String> fun1Map = new Dictionary<string, string>();
fun1Map.Add("userid", "test");
string response1 = InvokeOpenApi(HttpMethod.Get, releaseApiUrl, userId, key, "nbeport.cas.user.get", "json", "1.0", fun1Map);
Console.Write(response1);
Console.WriteLine();
Dictionary<String, String> fun2Map = new Dictionary<string, string>();
fun2Map.Add("number", "ONEYNB9BHC295400");
string response2 = InvokeOpenApi(HttpMethod.Get, releaseApiUrl, userId, key, "eportyun.logistics.subscribe.get", "json", "2.0", fun2Map);
Console.Write(response2);
Console.ReadLine();
}
}
}