ASP.NET后台手动调用POST提交并获取返回值 用于短信平台接口 支付宝接口

//这是一个短信平台的后台提交功能

string postData = string.Format("ECODE={0}&USERNAME={1}&PASSWORD={2}&MOBILE={3}&CONTENT={4}", ECODE, USERNAME, PASSWORD, MOBILE, CONTENT); // 要发放的数据 

byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);

HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create("http://n.020sms.com/MSMSEND.ewing"); //发送地址

objWebRequest.Method = "POST";//提交方式

objWebRequest.ContentType = "application/x-www-form-urlencoded";

objWebRequest.ContentLength = byteArray.Length;

Stream newStream = objWebRequest.GetRequestStream(); // Send the data. 

newStream.Write(byteArray, 0, byteArray.Length); //写入参数 

newStream.Close();



HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();//获取响应

StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);

string textResponse = sr.ReadToEnd() + "返回数据"; // 返回的数据

Response.Write(textResponse);//打印返回值

 

你可能感兴趣的:(asp.net)