Java 如何在请求RESTWeb服务时传递xml

Java 如何在请求RESTWeb服务时传递xml,java,android,Java,Android,我想通过请求将xml传递给RESTWeb服务。我不知道如何才能做到这一点 提前感谢。您不应该通过请求发送文件,您只需将该文件转换为您可以发送的内容即可。下面是一个示例:如果需要代码示例: String response = null; httppost = new HttpPost(URL_STRING); httppost.setParams(httpParams); String s = your_XML_Data_As_String_Or_JSON_Or_Wha

我想通过请求将xml传递给RESTWeb服务。我不知道如何才能做到这一点


提前感谢。

您不应该通过请求发送文件,您只需将该文件转换为您可以发送的内容即可。下面是一个示例:

如果需要代码示例:

String response = null;

    httppost = new HttpPost(URL_STRING);
    httppost.setParams(httpParams);

    String s = your_XML_Data_As_String_Or_JSON_Or_Whatever;

    try {

        StringEntity entity = new StringEntity(s);
        httppost.setEntity(entity);
        httppost.addHeader("Content-Type", "SomeMIMEType");

        response = httpclient.execute(httppost, handler);
        } catch (Exception e){
            e.printStackTrace }