zoukankan      html  css  js  c++  java
  • 请求一个短信接口,并接收该接口返回的状态值

      最近项目中用到发送验证码这个功能,需要请求一个短信接口,并且接收请求后返回的状态值,开始我觉得要抓取页面内容,然后自己也就这样做了,发现效果不理想,之后就放弃了。

      接着就百度了,有人提到用HttpWebRequest,觉得很惊奇,然后就去msdn上看了看这个类,发现还真的可以实现。接着就开始改代码。如下:

      

     1  Random random = new Random();
     2             string message = "您好,您此次操作的验证码为" + random.Next(100000, 999999);
     3             string url = "http://000.000.000.000/000/000?account=****&pswd=****&mobile=****&msg=内容&needstatus=true";
     4             HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
     5             req.Method = "POST";
     6             //req.Timeout = 5000;//请求超时时间
     7             string responseText = string.Empty;
     8             try
     9             {
    10                 WebResponse wr = req.GetResponse();
    11                 //在这里对接收到的页面内容进行处理    
    12                 StreamReader myreader = new StreamReader(wr.GetResponseStream(), Encoding.UTF8);
    13                 responseText = myreader.ReadToEnd();//HTML返回内容
    14                 string status = responseText.Split('
    ')[0].Split(',')[1];//获取返回的状态值 0为提交成功
    15                 req.Abort();
    16                 wr.Close();
    17             }
    18             catch (Exception ex)
    19             {
    20                 responseText = "NO:" + ex.Message.ToString();
    21             }
  • 相关阅读:
    oracle安装
    Jmeter入门篇
    DOS常用命令
    SpringBoot中使用JNnit4(一)之Mockito的使用
    SpringBoot中使用JNnit4(入门篇)
    SpringBoot搭建
    SpringBoot中集成Swagger2
    jpa使用过程中出现问题记录[持续更新]
    Python逆向(五)—— Python字节码解读
    Python逆向(四)—— Python内置模块dis.py源码详解
  • 原文地址:https://www.cnblogs.com/bobo-pcb/p/3571315.html
Copyright © 2011-2022 走看看