联系我们

为客户提供超预期的高品质网站设计!

.net发送post请求

2018-6-13 0:00:00

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 = "http://www.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;
    }
}

上一条新闻:js 去空格和替换sql注入
下一条新闻:asp.net 实体类 存入 数据库

 

4008-520-214 54057491 info@maolian.net