- Home /
POST using WWW isn't working
Hi there! I'm calling a restful web API from OnGUI() on clicking a GUI.Button. But the method I'm calling always gives me "500 Internal Server Error". I have tested the same web API using Simple REST Client (Chrome Plugin) and it works for the same data and url I'm using in the method below. Please help.
The code segment:
> function RestCallUsingPOST()
> {
> var strInput : String = "{\"uuid\":\"97182345\"}";
> var objHeaders : Hashtable = new Hashtable();
> objHeaders.Add("Content-Type","application/json");
>
> var body : byte[] = System.Text.Encoding.UTF8.GetBytes(strInput);
>
> var objPOST : WWW = new WWW("http://ec2-54-251-161-31.ap-southeast-1.compute.amazonaws.com/api/v1/user/GetUserBalance",
> body, objHeaders);
> yield objPOST;
>
> if(objPOST.error == null)
> {
> print(objPOST.text);
> }
> else
> {
> print("Web invoke error: "+objPOST.error);
> }
> }
A web-service should never return a 500 level error. Five hundred level errors mean that the server choked while handling the request. Ideally, if the request isn't properly formatted, then the appropriate response would be 400 (bad request). Is this a web-service that you've created, or are you hooking into someone else's web-service?
Please format your code, it's not hard and makes it easier for the people here to answer your question for free :) If you don't know how, watch the tutorial video
The code works fine, there was nothing wrong in the code above. It was a problem at web-service end. Thanks hiddenspring81 for showing me the path to server end, there's another which makes webservice so I had to sit with them to debug the request handling at webservice end.