【问题标题】:bulksms URI for retrieving messages sent用于检索已发送消息的 bulksms URI
【发布时间】:2018-05-07 13:33:46
【问题描述】:

BulkSMS,从数据范围(>= 或 >)中检索消息,没有施加的限制

Json 可以很好地发送和解析返回数据,它的提交 URI,我正在努力解决。我正在以正确的格式返回数据,但这还不够,所以它不是 URI 格式的过程。

底部代码:

经过一天有根据的猜测,该 URI 的正确语法应该是什么,并阅读了 api 手册,值得称赞的是,该手册中有很好的发送 SMS 消息的示例。

我猜这是主要目的。我正在尝试获取我们在某个日期范围内或自某个日期以来发送的邮件列表。

字符串 myURI = "https://api.bulksms.com/v1/messages?filter=submission.date%3E%3D2018-01-01T10%3A00%3A00%2B01%3A00";

编辑 - %3E 等于 > -------- %3D 等于 =

所以这个未编码意味着自年初以来的所有消息,但是 api 建议消息数量的限制是 1000,好吧,但是他们有一个可以添加的参数来覆盖这个,?limit =3000 例如

当我将它应用到我的 URI 时,我收到一个错误的请求错误 (400),有没有人有一些可能有效的示例?

api 文档: http://developer.bulksms.com/json/v1/#tag/Message%2Fpaths%2F~1messages%2Fget

干杯

    public static string GetListOfSMSMessages(string body)
    {       
     string myURI = "https://api.bulksms.com/v1/messages?filter=submission.date%3E%3D2018-01-01T10%3A00%3A00%2B01%3A00";
     string myUsername = "validusername";
     string myPassword = "validpassword";
     var request = WebRequest.Create(myURI);
     request.Credentials = new NetworkCredential(myUsername, myPassword);
     request.PreAuthenticate = true;
     request.Method = "GET";
     request.ContentType = "application/ascii"; //"application/json";
        try
        {
            // make the call to the API
            var response = request.GetResponse();
            // read the response and add to list
            List<string> outlist = new List<string>();
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                while (!reader.EndOfStream)
                {
                    outlist.Add(reader.ReadLine());
                }
            }
        }
        catch (WebException ex)
        {
            // show the general message
            Console.WriteLine("An error occurred:" + ex.Message);
            // print the detail that comes with the error
            var reader = new StreamReader(ex.Response.GetResponseStream());
            Console.WriteLine("Error details:" + reader.ReadToEnd());
            return "Failed";
        }
        return "Successful";

【问题讨论】:

  • 首先尝试使用 POSTMan 确保 url 和凭据都有效。看看:stackoverflow.com/questions/30481939/… 也许你不应该在传递给 Create 之前对 url 进行编码?
  • Leszek,谢谢。凭据是有效的,因为我说过我正在取回数据。确实我没有编码,不需要使用 GET 的 URI。
  • 您可能想添加 '&limit=3000' 而不是 '?limit=3000' & 以提供更多参数?

标签: c# bulksms


【解决方案1】:

这是一个在查询字符串中包含limit 的工作示例:

using System;
using System.IO;
using System.Net;
using System.Text;

    class MainClass
    {

        public static void Main(string[] args)
        {
            string myURI = "https://api.bulksms.com/v1/messages?filter=submission.date%3E%3D2018-01-01T10%3A00%3A00%2B01%3A00&limit=2";
            string myUsername = "someuser";
            string myPassword = "somepassword";
            var request = WebRequest.Create(myURI);
            request.Credentials = new NetworkCredential(myUsername, myPassword);
            request.PreAuthenticate = true;
            request.Method = "GET";
            request.ContentType = "application/json";
            try
            {
                // make the call to the API
                var response = request.GetResponse();

                // read the response and print it to the console
                var reader = new StreamReader(response.GetResponseStream());
                Console.WriteLine(reader.ReadToEnd());

            }  catch (WebException ex) {
                // show the general message
                Console.WriteLine("An error occurred:" + ex.Message);

                // print the detail that come with the HTTP error 
                var reader = new StreamReader(ex.Response.GetResponseStream());
                Console.WriteLine("Error details:" + reader.ReadToEnd());
            }

    }
}

【讨论】:

  • 谢谢 Willem 和 Leszek 都给出了正确的答案,BulkSMS 将其包含在他们的文档中是否太容易了...这里给我们所有技术人员的一课,注意细节,正确获取文档!
猜你喜欢
  • 2019-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-09
  • 1970-01-01
相关资源
最近更新 更多