【问题标题】:Parse.com Integration gives Bad request errorParse.com 集成给出了错误的请求错误
【发布时间】:2023-04-08 07:41:01
【问题描述】:

在我的网络管理员中,我必须集成 Parse.com 推送通知以将推送通知发送给订阅者。

我的问题是

我需要在我的 asp.net 管理员中将 REST API 与 curl 集成吗?要么 还有其他标准的 C# SDK 可以实现吗?

如果答案是 REST Api,那么与 REST api 集成的文档有以下示例。

卷曲 -X POST \

-H "X-Parse-Application-Id:" \

-H "X-Parse-REST-API-Key:" \

-H "Content-Type: application/json" \

-d '{"score":1337}' \

https://api.parse.com/1/classes/GameScore

我已经开始通过设置测试控制台应用程序来测试 url 来集成 REST API。我开发的应用程序代码如下。

    class Program
{
    private const string URL = "https://api.parse.com/1/classes/GameScore";
    private const string DATA = @"{""score"":1337";

    static void Main(string[] args)
    {
        Program.CreateObject();
        Console.ReadLine();
    }

    private static void CreateObject()
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
        request.Method = "POST";
        request.ContentType = "application/json";
        request.Headers.Add("X-Parse-Application-Id", "My Application ID given in example");
        request.Headers.Add("X-Parse-REST-API-Key", "the api key given in example");
        request.ContentLength = DATA.Length;
        StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
        requestWriter.Write(DATA);
        requestWriter.Close();

        try
        {
            WebResponse webResponse = request.GetResponse();
            Stream webStream = webResponse.GetResponseStream();
            StreamReader responseReader = new StreamReader(webStream);
            string response = responseReader.ReadToEnd();
            Console.Out.WriteLine(response);
            responseReader.Close();
        }
        catch (Exception e)
        {
            Console.Out.WriteLine("-----------------");
            Console.Out.WriteLine(e.Message);
        }
    }
}

代码给出 400 Bad request 错误

我不明白我错过了什么。

提前致谢

【问题讨论】:

    标签: c# api rest curl parse-platform


    【解决方案1】:

    DATA 缺少右大括号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-26
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多