Pessoal,
estou fazendo um metodo para consumir um ws (method: post, application/json)
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.calendario);
try
{
Map<String, String> dados = new HashMap<String, String>();
dados.put("idTurma", "60");
JSONObject jsonBody = new JSONObject(dados);
JsonObjectRequest request = new JsonObjectRequest(
Method.POST, URL, jsonBody,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(Calendario.this, "response: " + response, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(Calendario.this, "error: " + error.getMessage(), Toast.LENGTH_LONG).show();
}
})
{
@Override
protected Map<String,String> getParams()
{
params = new HashMap<String, String>();
params.put("idTurma", "60");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
//headers.put("Content-Type", "text/plain");
//headers.put("Content-Type", "application/json");
headers.put("Content-Type", "application/x-www-form-urlencoded, application/json; charset=utf-8");
//headers.put("Content-Type", "application/x-www-form-urlencoded");
return headers;
}
};
Volley.newRequestQueue(this).add(request);
}
catch (Exception e)
{
e.printStackTrace();
}
Mas dá o seguinte erro:
Advertência: StandardWrapperValve[br.com.bkids.rest.ApplicationConfig]: Servlet.service() for servlet br.com.bkids.rest.ApplicationConfig threw exception
org.glassfish.jersey.message.internal.HeaderValueException: Too many "Content-Type" header values: "[application/x-www-form-urlencoded, application/json; charset=utf-8, application/json; charset=utf-8]"
at org.glassfish.jersey.message.internal.InboundMessageContext.singleHeader(InboundMessageContext.java:301)
at org.glassfish.jersey.message.internal.InboundMessageContext.getMediaType(InboundMessageContext.java:427)
at org.glassfish.jersey.servlet.WebComponent.filterFormParameters(WebComponent.java:482)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:303)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
Lembrando que já tentei enviar sem Contenty-Type, tentei enviar apenas “application/json”