如何处理解析存储在代理服务器后面的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我假设这是因为文件在代理服务器上。这是我的问题的原因吗?如果是这样的话,处理代理服务器上的文件的正确方式是什么?
发布于 2013-10-01 06:40:46
您可以使用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(); https://stackoverflow.com/questions/17352334
复制相似问题