.net发送post请求
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using Newtonsoft.Json.Linq;
public partial class getWeiZhangCityFromBaiJie : System.Web.UI.Page
{
private const String host = "maolian.com/";
private const String method = "POST";
private const String user = "jingdoxiang";
private const String token = "3ee94880f71";
private const String api = "Opens";
protected void Page_Load(object sender, EventArgs e)
{
WebRequest request7 = WebRequest.Create(host);
request7.Method = method;
string postdata = "user=jingdongwanxiang&token=36a8c5e426563ac7aceebbee94880f71&api=Opens";
// byte[] bytes = Encoding.ASCII.GetBytes(postdata); //如果页面是gb2312的编码就选这个
byte[] bytes = Encoding.UTF8.GetBytes(postdata);
request7.ContentType = "application/x-www-form-urlencoded";
request7.ContentLength = postdata.Length;
Stream sendStream = request7.GetRequestStream();
sendStream.Write(bytes, 0, bytes.Length);
sendStream.Close();
WebResponse response7 = request7.GetResponse();
string OrderQuantity = new StreamReader(response7.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
//string OrderQuantity = new StreamReader(response7.GetResponseStream(), Encoding.GetEncoding("gb2312")).ReadToEnd();//如果页面是gb2312的编码就选这个
JObject jo = JObject.Parse(OrderQuantity);
Response.Write(jo);
////解析josn
}
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
}