BulkSMS,从数据范围(> =或>)中检索邮件而不施加限制
Json可以发送和解析返回数据,提交URI,我正在努力。我正在以正确的格式返回数据,但还不够,因此它不是URI格式的过程。
底部的代码:
经过一天的教育猜测,该URI的正确语法应该是什么,并阅读api手册,其中包含发送短信的绝佳示例。
这是我猜的主要目的。我正在尝试获取我们为日期范围或特定日期发送的邮件列表。
string myURI =“https://api.bulksms.com/v1/messages?filter=submission.date%3E%3D2018-01-01T10%3A00%3A00%2B01%3A00”;
编辑 - %3E等于> --------%3D等于=
所以这个未编码意味着自年初以来的所有消息,但是api建议消息数量的限制是1000,好吧,但是他们有一个可以添加的参数来覆盖这个,?限制例如= 3000
当我将此应用于我的URI时,我收到错误的请求错误(400),是否有人有一些可能有用的示例?
api doc: 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";
答案 0 :(得分: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());
}
}
}