c# 请求第三方地址,接受返回的json数据
///
/// 根据url地址 获取返回的json数据
///
///
///
public static string GetSource(string _url)
{
HttpWebRequest myWebRequest = (System.Net.HttpWebRequest)WebRequest.Create(_url);
myWebRequest.Method = "POST";
myWebRequest.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse myWebResponse = (System.Net.HttpWebResponse)myWebRequest.GetResponse();
StreamReader reader = new StreamReader(myWebResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("utf-8"));
byte[] buffer = Encoding.GetEncoding("utf-8").GetBytes(reader.ReadToEnd());
string html = Encoding.GetEncoding("utf-8").GetString(buffer).Trim();
return html;
}
string json = "";
RequestBack obj = null;
try
{
WebPublic.Log("会员“"+WebPublic.GetUserName()+ "”充值进入下单接口,请求地址:"+ url);
json = PayClass.GetSource(url);
obj = (RequestBack)JsonConvert.DeserializeObject(json, typeof(RequestBack));
}
catch (Exception ex)
{
WebPublic.Log("会员“" + WebPublic.GetUserName() + "”充值进入下单接口异常:" + ex.Message );
Response.Redirect("/My/Pay.aspx?PayID=201");
}