[英]UnityWebRequest - error: 415 Unsupported Media Type
I'm preparing my game for publishing on ArmorGames.com I use their API to get the id of the current user:我正在准备我的游戏在 ArmorGames.com 上发布我使用他们的API来获取当前用户的 ID:
https://services.armorgames.com/services/rest/v1/authenticate/user.json https://services.armorgames.com/services/rest/v1/authenticate/user.json
When I click on this link in the browser, I get the correct answer.当我在浏览器中点击这个链接时,我得到了正确的答案。 When sending a GET request through my build, I get an error:通过我的构建发送 GET 请求时,出现错误:
HTTP / 1.1 415 Unsupported Media Type HTTP / 1.1 415 不支持的媒体类型
IEnumerator GetText(Action<string> callback)
{
string url;
url = "https://services.armorgames.com/services/rest/v1/authenticate/user.json";
UnityWebRequest www = UnityWebRequest.Get(url);
www.SetRequestHeader("Content-Type", "application/json");
www.SetRequestHeader("accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" );
www.SetRequestHeader("accept-encoding", "gzip, deflate, br");
www.SetRequestHeader("accept-language", "ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7");
yield return www.SendWebRequest();
if(www.isNetworkError || www.isHttpError) {
Debug.Log("MyError: " + www.error);
callback(null);
}
else {
Debug.Log("resp:" + www.downloadHandler.text);
callback(www.downloadHandler.text);
}
}
I try to send request with headers and without.我尝试发送带有标头和不带标头的请求。 Nothing helps.没有任何帮助。 What can be the problem?可能是什么问题?
Seems a bit of googling was in order.似乎有点谷歌搜索是为了。
https://forum.unity.com/threads/unitywebrequest-error-415-unsupported-media-type.801297/ https://forum.unity.com/threads/unitywebrequest-error-415-unsupported-media-type.801297/
Which isnt obvious from your pasted code although the lack of colouring in visual studio gave it away尽管 Visual Studio 中缺少着色,但这从您粘贴的代码中并不明显
there is a space after user.用户后有一个空格。 and json..和 json..
remove the space删除空间
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.