rest - Server internal error with post request in api restful -
i'm having problems post requests in api restful i'm testing , don't see error.
here i've api
import javax.ws.rs.consumes; import javax.ws.rs.get; import javax.ws.rs.post; import javax.ws.rs.path; import test.api.models.test; import test.api.mediatype; @path("/test") public class testresource { @get public string getsomething(){ return "ok get"; } @post @consumes(mediatype.test) public string postsomething(test test){ system.out.println("got: " + test); return "ok post"; } }
the problem when request localhost:8080/test-api/test postman application, "ok get". if post request 500 server error. i'm setting correctly content-type header field. error is:
"message": "http 500 internal server error", "status": 500
and how i'm sending data:
{ "a": "one", "b": "two" }
i think problem can in test class, because if change input parameter of postsomething method string type "ok post".
here test class don't see strange...
public class test { public string a; public string b; public test ( string a, string b){ this.a = a; this.b = b; } public string geta() { return a; } public void seta(string a) { this.a = a; } public string getb() { return b; } public void setb(string b) { this.b = b; } }
anyone see strange?
thank you.
the problem maybe post data, maybe have url encode post data. try following post data, it's url encoded.
%7b%22a%22%3a%20%22one%22%2c%22b%22%3a%20%22two%22%7d
or can try http://meyerweb.com/eric/tools/dencoder/ encode own data.
Comments
Post a Comment