Android:关于XML帖子的400个错误请求

时间:2014-10-15 13:56:36

标签: android xml post http-post bad-request

我正在研究android REST应用程序。我正在尝试在doBackground()中使用XML内容执行POST方法,但服务器返回 400错误请求

我的客户代码:

private class HttpRequestTask extends AsyncTask<Void, Void, User> {

@Override
protected User doInBackground(Void... params) {

    // serialisation xml
    Serializer serializer = new Persister();
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    try {
        serializer.write(profil, out);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String serializedProfil = out.toString();

    // creation de la requete post
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://X.X.X.X:8080/webservices/inscription");

    try {
        post.addHeader("Accept", "text/plain");
        post.addHeader("Content-Type", "application/xml");

        StringEntity entity = new StringEntity(serializedProfil);
        post.setEntity(entity);

        HttpResponse httpResponse = client.execute(post);

    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

}

我试图达到的服务标题......

@POST
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces(MediaType.TEXT_PLAIN)
public String inscrire(@Context HttpServletRequest req, JAXBElement<User> JaxbUser) {
           ...
}

任何想法? 感谢

0 个答案:

没有答案