Post返回json值
List<KeyValuePair<string, string>> PostData = new List<KeyValuePair<string, string>>();
PostData.Add(new KeyValuePair<string, string>("event_id", "loan_web"));
public static FraudApiResponse TonDun(List<KeyValuePair<string, string>> Params, string uri, int Timeout = 500)
{
try
{
//byte[] data = Encoding.UTF8.GetBytes(postData);
//Uri uRI = new Uri(uri);
HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
req.Method = "POST";
req.Timeout = Timeout;
req.ContentType = "application/x-www-form-urlencoded";
//req.ContentLength = data.Length;
req.AllowAutoRedirect = true;
req.KeepAlive = true;
req.Proxy = null;
List<string> Parameter = new List<string>(Params.Count);
foreach (KeyValuePair<string, string> item in Params)
{
Parameter.Add(String.Concat(item.Key, "=", item.Value));
}
string PostData = String.Join("&", Parameter.ToArray());
Stream RequestStream = req.GetRequestStream();
using (StreamWriter RequestStreamWriter = new StreamWriter(RequestStream, new UTF8Encoding(false)))
{
RequestStreamWriter.Write(PostData);
RequestStreamWriter.Flush();
}
WebResponse Response = req.GetResponse();
Stream ResponseStream = Response.GetResponseStream();
StreamReader ResponseStreamReader = new StreamReader(ResponseStream, Encoding.UTF8);
FraudApiResponse Result = JsonConvert.DeserializeObject<FraudApiResponse>(ResponseStreamReader.ReadToEnd());
return Result;
}
catch (Exception ex)
{
FraudApiResponse Result = new FraudApiResponse();
Result.hit_rules = new List<HitRule>(0);
Result.policy_set = new List<Policy>(0);
return Result;
}
}