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);//打印返回值
摘自 yagene
下一篇: Android 请求网络接口实现方法