通过链接调用方法

        /// <summary>
        /// 通过链接调用方法
        /// </summary>
        /// <param name="Url">链接</param>
        /// <param name="postDataStr">传入参数</param>
        /// <returns></returns>
        public string HPost(string Url, string postDataStr)
        {
            string retString = "";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
            request.Method = "POST";
            request.ContentType = "application/json";
            request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
            Stream myRequestStream = request.GetRequestStream();
            StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
            myStreamWriter.Write(postDataStr);
            myStreamWriter.Close();
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();
            return retString;
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            string SYSSerialNo = "SYS20170315003";
            string item = "181119071001378";
            string token = "b9cddf7dcc584baa94448b71562c9f44";
            string PostMsg = "{\"head\":{\"transCode\":\"P1007\",\"transId\":\"20180710105959JEj5\"},\"body\":{\"sys\":\"" + SYSSerialNo + "\",\"order_sn\":\"" + item + "\"}}";
            string Url = "https://a.asus.com.cn/channel/v1.0/SYCBD/PPQybOrder?appid=WHlejuMgmW9S&token=" + token;
            //获取接口返回值
            string RequestMsg = HPost(Url, PostMsg);
            JObject jo = (JObject)JsonConvert.DeserializeObject(RequestMsg);
        }

 

  

转载于:https://www.cnblogs.com/suflowers1700218/p/11205431.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值