0

如何处理解析存储在代理服务器后面的 XML 文件?我有以下代码:

import java.io.IOException;
import java.net.URL;

import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class FileParsing {
    public static void parseXMLFile(String xmlFilePath) throws IOException, JDOMException {
            URL xmlFileURL = new URL(xmlFilePath);
            SAXBuilder builder = new SAXBuilder();
            Document xmlDoc = builder.build(xmlFileURL);

            // File parsing code...
    }
}

现在我得到这个例外:

 java.io.IOException: Server returned HTTP response code: 502 for URL: https://proxyserver.com/xmlFileOfInterest.xml

我假设这是因为该文件位于代理服务器上。这是我的问题的原因吗?如果是这样,处理代理服务器上的文件的正确方法是什么?

4

1 回答 1

0

你可以使用 apache webclient 来解析它

WebClient client = WebClient.create(xmlFilePath
                ,String.class,null);    
        client = client.type(MediaType.APPLICATION_XML);

HTTPConduit httpConduit = (HTTPConduit)WebClient.getConfig(client).getConduit();
        HTTPClientPolicy policy = new HTTPClientPolicy();               
        policy.setProxyServer(proxyurl);
        policy.setProxyServerPort(8080);
        httpConduit.setClient(policy);

    Response r = client.post(); 
InputStream response= (InputStream)r.getEntity();   
于 2013-09-30T22:40:46.410 回答