【问题标题】:Curl to C# user flag卷曲到 C# 用户标志
【发布时间】:2014-05-23 12:16:23
【问题描述】:

我正在尝试在 C# 中为 Pushbullet API 重现此 Curl 调用。

curl https://api.pushbullet.com/v2/pushes \
      -u <your_api_key_here>: \
      -d device_iden="<your_device_iden_here>" \
      -d type="note" \
      -d title="Note title" \
      -d body="note body" \
      -X POST

这是我复制它的代码:

var response = default(IRestResponse);
var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Json };
var client = new RestClient();
client.BaseUrl = "https://api.pushbullet.com/v2/";
request.Resource = "pushes";
var bodyInformation = string.Concat(" { \"", Config.Settings.PushbulletAPIKey,
                        "\": { \"type\":\"note\", \"title\":\"", title, "\", \"body\":\"", message, "\" } }");
request.AddBody(bodyInformation);
response = client.Execute(request);

当我发送它时,它会返回:

{"error": {"message": "authentication token is missing or invalid.", "type": "invalid_user"}}

API 页面供参考:

https://docs.pushbullet.com/

https://docs.pushbullet.com/v2/pushes

【问题讨论】:

  • 我假设这是一个错字? request.AddBody(bodtInformation);
  • PushBullet API Auth?的可能重复
  • 那是我修正的错字仍然不行。

标签: c# curl restsharp


【解决方案1】:

您在正文中传递凭据,而不是设置客户端的 Authenticator 属性以使用基本身份验证传递它们。

curl -u 开关使用用户名:密码凭据对服务器进行基本身份验证。您发布的声明使用 API 密钥作为用户名和空密码。

你应该使用类似的东西:

client.Authenticator = new HttpBasicAuthenticator(
                               Config.Settings.PushbulletAPIKey, "");

【讨论】:

  • 谢谢!像魅力一样工作!
猜你喜欢
  • 2019-02-25
  • 1970-01-01
  • 1970-01-01
  • 2015-02-01
  • 1970-01-01
  • 2016-01-18
  • 2014-05-29
  • 1970-01-01
相关资源
最近更新 更多