标签: restsharp

是否可以使用Twilio-csharp/TwilioRestClient发送带有SMSMessage的cookie?

我正在创建出站短信通信,需要设置一个cookie,以便我可以跟踪对话线程.我正在使用Twilio-charp客户端,但没有找到设置cookie或http标头的方法.这是可能的还是我需要追求不同的路线?

编辑:

我需要在这里阐明一下.在我的场景中,我需要设置一个cookie,其中包含需要包含在原始出站消息中的事务ID.例如,我将创建一条SMS消息,该消息将请求用户的响应:"文本(1)批准,(2)拒绝".

Twilio示例代码详细说明了一个页面,它接收消息,检查cookie,然后创建一个cookie(如果它尚不存在).在我的场景中,我需要cookie在出站消息中.

twilio restsharp

1
推荐指数
1
解决办法
973
查看次数

如何使用非法的json字段名重命名和重新映射字段

我已经使用json2csharp来生成一些很好的c#类,我可以将其反序列化为json.

它实际上按预期工作除了json2csharp命名的一些字段invalid_name.我将它们重命名为有效的csharp名称,但在序列化时,这些类为null.

我找到了另一个SO帖子 ......其中一个回答者说下面的......

请记住,由于json中某些字段的命名,我在下面粘贴的类将无法直接使用.您可能必须手动重命名它们并映射它们.

这准确地描述了我的问题.不幸的是,答案没有给出实际如何"映射它们"的线索.那么有人可以告诉我如何手动将一些json数组映射到c#类.

我正在使用RestSharp反序列化器,顺便说一句.

有任何想法吗?

c# json restsharp deserialization json2csharp

1
推荐指数
1
解决办法
1924
查看次数

Restsharp XML请求

我试图通过一个带有restsharp的API来提供一些数据.

从API的手册中,PUT调用使用:template params id string barcode string

查询参数字符串运算符字符串c long

请求应具有自定义标头:Name ="Content-Type"Value ="application/xml"

有人能告诉我如何使用restsharp发布这样的请求吗?

c# restsharp

1
推荐指数
1
解决办法
9058
查看次数

Restsharp 异常无法识别 URI 前缀

我从 RestSharp 得到一个例外,但The URI prefix is not recognized不知道为什么。

参数

requestBody 只是一个 POCO

domainsome.company.com

_config.AddPersonEndpointapi/person/add

public PersonResponse AddPerson(PersonRequest requestBody, string domain)
{
    var client = new RestClient(domain);

    var request = new RestRequest(_config.AddPersonEndpoint, Method.POST);
    request.RequestFormat = DataFormat.Json;
    request.AddBody(requestBody);

    var response = client.Execute<PersonResponse>(request);

    if (response.ErrorException != null)
        throw response.ErrorException;

    if (response.ErrorMessage != null)
        throw new PortalConnectivityException(response.ErrorMessage);

    if (!string.IsNullOrEmpty(response.Data.ErrorMessage))
        throw new PortalException(response.Data.ErrorMessage);

    return response.Data;

}
Run Code Online (Sandbox Code Playgroud)

c# restsharp

1
推荐指数
1
解决办法
2217
查看次数

如何使用restsharp在电子邮件中附加memorystream对象?

我想知道您是否可以帮我使用RestSharp为电子邮件附件添加MemoryStream附件对象?

这是我从MailGun获得的代码,但它在此示例中附加了一个物理文件:

谢谢.

public static IRestResponse SendComplexMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnXXXXXXXX");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <me@samples.mailgun.org>");
       request.AddParameter("to", "foo@example.com");
       request.AddParameter("cc", "baz@example.com");
       request.AddParameter("bcc", "bar@example.com");
       request.AddParameter("subject", "Hello");
       request.AddParameter("text", "Testing some Mailgun awesomness!");
       request.AddParameter("html", "<html>HTML version of the body</html>");

// I need to add memorystream object here ---
       request.AddFile("attachment", Path.Combine("files", "test.jpg"));
       request.AddFile("attachment", Path.Combine("files","test.txt"));
// -------------------------------------------

       request.Method = Method.POST;
       return client.Execute(request);
}
Run Code Online (Sandbox Code Playgroud)

email memorystream attachment restsharp

1
推荐指数
1
解决办法
1783
查看次数

获取错误:找不到方法:'Void RestSharp.RestClient.set_BaseUrl(System.String)'.在Twilio-CSharp

我正在使用MVC5应用程序并实现twilio rest api用于发送短信但我收到错误:

 var twilio = new TwilioRestClient(AccountSid, AuthToken);
Run Code Online (Sandbox Code Playgroud)

我的restsharp dll版本是105.0.1,而且我有104.4.0的旧版本,我尝试了twilio最新版本和旧版本,但似乎得到了错误.

类型"system.missingMethodException而"的例外发生在Nop.Plugin.SMSProvider.nopSMS.dll但在用户代码中没有处理

附加信息:找不到方法:'Void RestSharp.RestClient.set_BaseUrl(System.String)'.

我该怎么办?

c# dependencies nopcommerce twilio restsharp

1
推荐指数
1
解决办法
2885
查看次数

RestSharp 序列化 JSON 数组以请求参数

我不是想只发布 JSON,而是想将 JSON数组发布到发布请求的一个参数。

代码:

        var locations = new Dictionary<string, object>();
        locations.Add("A", 1);
        locations.Add("B", 2);
        locations.Add("C", 3);

        request.AddObject(locations);
        request.AddParameter("date", 1434986731000);
Run Code Online (Sandbox Code Playgroud)

AddObject 失败,因为我认为新的 RestSharp JSON 序列化程序无法处理字典。(这里的错误:http : //pastebin.com/PC8KurrW

我也尝试过,request.AddParameter("locations", locations); 但根本没有序列化为 json。

我希望请求看起来像

locations=[{A:1, B:2, C:3}]&date=1434986731000

[]很重要,即使它只有 1 个 JSON 对象。它是一个 JSON 对象数组。

c# serialization json restsharp

1
推荐指数
1
解决办法
5479
查看次数

如何将RestSharp响应解析为类?

我正在使用RestSharp处理发送电子邮件,我需要能够检查响应以确保一切正常.

我对JSON一无所知,但是我从搜索中看到的东西让我相信调用会client.Execute<T>( Foo )导致我得到一个类型的对象,T其中包含由请求执行结果填充的属性...

不是这种情况.

在我故意使POST失败的情况下,我从response.Content属性获取此信息:

{"error":3,"message":"Wrong credentials specified"}
Run Code Online (Sandbox Code Playgroud)

当我使用适当的凭据提交请求时,response.Content看起来像这样:

{"message":"OK"}
Run Code Online (Sandbox Code Playgroud)

这让我相信创建一个这样的课程应该是我需要的一切:

public class RestMessage {
    string error { get; set; }
    string message { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

但是当我打电话的时候

IRestResponse<RestMessage> Foo = Bar.Execute<RestMessage>( Baz );
Run Code Online (Sandbox Code Playgroud)

Foo.Data等于一个类型的对象RestMessage,但在任何一种情况下,结果总是那样error = null(在后一种情况下有意义,但在前一种情况下没有意义)和message = null.

显然,它并不像我读过的每个例子那样简单.

我已经在VS2015社区的NuGet中安装了RestSharp,使用了他们非常棒的NuGet ... thingy所以我有最新的版本.

有人可以解释我如何能够完成我想对我做的事情,好像我还在出牙吗?

c# json restsharp deserialization

1
推荐指数
1
解决办法
4004
查看次数

RestSharp:无法将类型为“ RestSharp.JsonArray”的对象转换为类型为“ System.Collections.Generic.IDictionary”的对象

到目前为止无法解决问题:无法将类型为'RestSharp.JsonArray'的对象转换为类型为'System.Collections.Generic.IDictionary`2 [System.String,System.Object-我在这里可以在响应本身:

var response = client.Execute<ThirdPartySuggester>(request);
Run Code Online (Sandbox Code Playgroud)

但是我得到的NullReferenceExeption在这里:

var name = response.Data.Name;
Run Code Online (Sandbox Code Playgroud)

这是我的测试课:

    public class Class1
    {
        [Theory]
        [InlineData("apple", "en-us")]
        public void SearchTest(string searchPhrase, string language)
        {
            var client = new RestClient("https://test_site/api");
            var request = new RestRequest("/thirdparty/suggester?searchPhrase={search_key}&marketLocale={language_id}", Method.GET);
            request
                .AddUrlSegment("search_key", searchPhrase)
                .AddUrlSegment("language_id", language);
            var response = client.Execute<ThirdPartySuggester>(request);

            var name = response.Data.Name;
            var manufacturer = response.Data.Manufacturer;
            var deviceType = response.Data.DeviceType;
            var searchKey = response.Data.SearchKey;

.....
Run Code Online (Sandbox Code Playgroud)

我得到的响应包含以下数据:

[
  {
    "name": "iPhone 7 Plus",
    "manufacturer": "Apple",
    "deviceType": "smartphone_tablet",
    "searchKey": "apple_iphone_7_plus"
  },
  {
    "name": "iPhone …
Run Code Online (Sandbox Code Playgroud)

c# restsharp deserialization

1
推荐指数
1
解决办法
4926
查看次数

格式化json String并将其传递给具有参数的主体给出错误

我正在尝试使用RestSharp创建一个post请求.

我有以下字符串

"{ \"name\": \"string\", \"type\": \"string\", \"parentId\": \"string\", \"Location\": [ \"string\" ]}"
Run Code Online (Sandbox Code Playgroud)

我需要将它传递到json主体发送POST请求我正在尝试以下.

public IRestResponse PostNewLocation(string Name, string Type, Nullable<Guid> ParentId, string Locatations)
{
  string NewLocation = string.Format("{ \"name\": \"{0}\", \"type\": \"{1}\", \"parentId\": \"{2}\", \"Location\": [ \"{3}\" ]}", Name, Type, ParentId, Location);
  var request = new RestRequest(Method.POST);
  request.Resource = string.Format("/Sample/Url");
  request.AddParameter("application/json", NewLocation, ParameterType.RequestBody);
  IRestResponse response = Client.Execute(request);
}
Run Code Online (Sandbox Code Playgroud)

而错误

Message: System.FormatException : Input string was not in a correct format.
Run Code Online (Sandbox Code Playgroud)

如何格式化上面的字符串以将其传递到json正文?

我的测试在这一行失败了

string NewLocation = string.Format("{ \"name\": \"{0}\", \"type\": …
Run Code Online (Sandbox Code Playgroud)

c# api restsharp

1
推荐指数
1
解决办法
653
查看次数