- Home /
Json return 405 status code when posting
Hello,
Im using the SimpleJSON as a JSON builder and parser.
link text
For the Json "database" im using jsonblob:
link text
Here is my sample Json "database":
link text
I would like to add the jsonString as in my code below to the json "database" but I get a 405 status error. Can anyone give the a possible solution?
using System.Collections;
using System.Text;
using UnityEngine;
using SimpleJSON;
using UnityEngine.Networking;
public class Account: MonoBehaviour
{
// ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
public GameManager gameManager;
public string score = "null";
// ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
void Start()
{
StartCoroutine(WriteData("https://jsonblob.com/8da66507-afab-11e7-b7f1-47b394d73ab7"));
}
// ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
IEnumerator WriteData(string url)
{
var n = new JSONObject ();
n ["score"] = score;
string jsonString = n.ToString ();
var request = new UnityWebRequest(url, "POST");
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonString);
request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
request.SetRequestHeader("Content-Type", "application/json");
yield return request.Send();
Debug.Log("Status Code: " + request.responseCode);
}
// ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
}
Answer by Bunny83 · Oct 13, 2017 at 02:00 AM
You haven't yet reponded to my answer over here. You used a POST request while the API does expect a PUT request when you want to update an existing blob. A POST request must not use an existing blob ID as it creates a new blob. Just read the API specification carefully.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
The Object you want to Instantiate is null 0 Answers
Instantiate a sprite using json data value (C# Unity) 2 Answers
JsonUtility with openweatherAPI 1 Answer