httpClient.executeMethod抛出意外的404 - 无法解释的截断URL

时间:2015-02-02 22:24:48

标签: java http soap apache-httpclient-4.x

此处使用的网址仅供参考,原因是问题的隐私性,我正面临着。

我的soapAction网址格式正确,我的请求也是一个很好的肥皂请求。我错误的是我的网址是https://www.macy.com/we.like.to.buy.discounts,这是我得到的404错误,基本上肥皂响应是截断我原来的网址:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /we.like.to.buy.discounts was not found on this server.</p>
</body></html>

通过调试代码挖掘一下,似乎post对象的path属性的值为/we.like.to.buy.discounts,其中不正确网址和HttpHost属性www.macy.com。我不明白为什么客户端没有发送完整的URL而只是发送截断的URL。请帮忙。

原始代码在这里:

public static void service(String request, String webServiceURL)
            throws IOException {
        boolean status = false;
        String soapAction = webServiceURL;
        HttpClient client= new HttpClient();        
        PostMethod post= new PostMethod(soapAction);
        client.executeMethod(post);
        InputStream is = null;
        try {
            is = new ByteArrayInputStream(request.getBytes("UTF-8"));
            InputStreamRequestEntity requestEntity = new InputStreamRequestEntity(is, "text/xml");
            post.setRequestEntity(requestEntity);
            client.executeMethod(post);         
            String soapRes = post.getResponseBodyAsString();
            System.out.println("Soap Response:" + soapRes);

            if (!soapRes.contains("YourMAMA")) {
                status = false;
            } else {
                status = true;
            }
        } finally {
            is.close();
            post.releaseConnection();
        } 

    }

0 个答案:

没有答案