微信支付返回xml格式错误

微信支付统一下单返回

 <xml><return_code><![CDATA[FAIL]]></return_code>
           <return_msg><![CDATA[XML格式错误]]></return_msg>
           </xml>

,如何解决,我是用 public static byte[] httpPost(String url, String entity) {
if (url == null || url.length() == 0) {

        return null;
    }

    HttpClient httpClient = getNewHttpClient();

    HttpPost httpPost = new HttpPost(url);



    try {
        httpPost.setEntity(new StringEntity(entity));
        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-type", "application/json");

        HttpResponse resp = httpClient.execute(httpPost);
        if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {

            return null;
        }

        return EntityUtils.toByteArray(resp.getEntity());
    } catch (Exception e) {

        e.printStackTrace();
        return null;
    }
}

private static HttpClient getNewHttpClient() {
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new SSLSocketFactoryEx(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "UTF-8");

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

        return new DefaultHttpClient(ccm, params);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

访问微信的api的,请大神帮忙。

@zhiqiang9267你解决xml格式不对这个错误了吗?怎么解决的?求分享

仔细检查下entity和官方示例的格式仔细对比下,顺序都要一致。
下面两行不要
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
明明是xml的,搞成json干嘛。

httpPost.setEntity(new StringEntity(entity, "UTF-8")); 最好这样。

如果还是搞不定,下载demo,看看官方源码。

怎么解决的,求方法,,谢谢