java - JAX-RS response.getEntity returns null after post -


when invoke next code:

response response = target.request(mediatype.application_json_type)                 .post(entity.entity(form, mediatype.application_form_urlencoded_type));  response.getentity(); 

response.getentity() null.

but when invoke:

jsonobject json = target.request(mediatype.application_json_type)                 .post(entity.entity(form, mediatype.application_form_urlencoded_type), jsonobject.class); 

variable json not null.

i need use first variant because need check response status.

why first code not working?and how can status code then?

you need use response.readentity(your.class) return instance of type want. example

string rawjson = response.readentity(string.class); // or jsonobject jsonobject = response.readentity(jsonobject.class); 

note there needs provider handle reading java type , application/json. if using jersey , json-p api, see this. general information providers, see this


Comments

Popular posts from this blog

angular ui router - 10 digest iterations reached in angularjs when using $state.go -

javascript - Can Piwik report referrer in real time? -

asp.net - Google Drive Access: At least one client secrets (Installed or Web) should be set -