gpt4 book ai didi

ios - 解析推送 REST API 错误 400 "Bad Request"

转载 作者:可可西里 更新时间:2023-11-01 05:53:55 27 4
gpt4 key购买 nike

我正在使用 Xamarin iOS 和 MonoGame 开发适用于 iOS 的应用程序。我想通过他们的 REST API 使用 Parse 的推送通知,所以首先我必须创建一个安装对象:

var bundle = new Dictionary<string, object>();
bundle.Add("channels", "");
bundle.Add("deviceType", "ios");
bundle.Add("deviceToken", _deviceToken);

string urlpath = "https://api.parse.com/1/installations";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(urlpath);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add("X-Parse-Application-Id", _parseAppID);
httpWebRequest.Headers.Add("X-Parse-REST-API-KEY", _parseRestAPIKey);
httpWebRequest.Method = "POST";
string bundleString = bundle.ToJson();
byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes(bundleString);
string result = Convert.ToBase64String(buffer);
StreamWriter requestWriter = new StreamWriter(httpWebRequest.GetRequestStream());
requestWriter.Write(result, 0, result.Length);
requestWriter.Close();
WebResponse httpResponse = await httpWebRequest.GetResponseAsync();

Stream stream = httpResponse.GetResponseStream();
string json = string.Empty;

using (StreamReader reader = new StreamReader(stream))
{
while (!reader.EndOfStream)
{
json += reader.ReadLine();
}
}

JsonObject jsonObject = JsonObject.Parse(json);
_varStorage.Save("ObjectId", jsonObject.Get<string>("objectId"));

bundleString 值为:

"{\"channels\":\"\",\"deviceType\":\"ios\",\"deviceToken\":\"46becd0a165be042eeab5a1ec96b8858065cbea7311479da16c0fd1c9428e2eb\"}"

此代码引发 System.Net.WebExceptionStatus.ProtocolError 错误 400“错误请求”,我不明白为什么。

最佳答案

根据文档 https://www.parse.com/docs/rest#installations, channel 应该是一个字符串数组

bundle.Add("channels", new [] { "" });

关于ios - 解析推送 REST API 错误 400 "Bad Request",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24480257/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com