0

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";
4

1 回答 1

0

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());
            }

    }
}
于 2018-05-07T05:24:28.170 回答