xiaolaotou12
rosauron
2016-07-15 09:33

httpclient 发送post请求(https),请求体为xml的字符串类型,获取不到数据

图片说明
用fiddler发送请求可以获取到参数,但是用httpclient返回500;求解答
(下面是我的部分代码)
ProtocolSocketFactory fcty = new MySecureProtocolSocketFactory();
Protocol.registerProtocol("https", new Protocol("https", fcty, 443));

    String response = null;
    HttpClient client = new HttpClient();

    PostMethod postMethod = new PostMethod(url);
    postMethod.getParams().setParameter(
            HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");

    // 设置Post数据
    if (!params.isEmpty()) {
        String data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><EntityPreMethod><Method>"
                + params.get("Method")
                + "</Method><Parameters>"
                + params.get("Parameters")
                + "</Parameters><AccessId>******</AccessId></EntityPreMethod>";
        System.out.println(data);
        postMethod.setRequestEntity(new StringRequestEntity(data,
                "text/xml", "gbk"));
        postMethod.addRequestHeader("Authorization",
                "Bearer  " + this.getAccessToken());
        postMethod.setRequestHeader("Content-Type", "text/xml");
    }
    try {
        int statusCode = client.executeMethod(postMethod);
        System.out.println(statusCode);
        if (statusCode == HttpStatus.SC_OK) {
            response = postMethod.getResponseBodyAsString();
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换