阅读此页面http://www.forcedisturbances.com/2012/07/downloading-visual-force-pages-that-are.html,我尝试了此代码,但它似乎对我不起作用。
ConnectorConfig config = new ConnectorConfig();
config.setUsername(USERNAME);
config.setPassword(PASSWORD);
connection = Connector.newConnection(config);
URL url = new URL("https://c.na14.visual.force.com/apex/ReportPrintOut?id=");
url.openConnection().addRequestProperty("Authorization", "Bearer " + config.getSessionId());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
我可以验证 salesforce 连接器对象是否成功,因为我没有抛出无效登录异常,并且可以成功查询数据。URL调用得到的url数据如下,说明session id有问题。但是我无法弄清楚问题是什么。
HTTP Code: 200
<script>
if (window.location.replace){
window.location.replace('https://login.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.na14.visual.force.com%252Fapex%252FReportPrintOut%253Fid%253D');
} else {;
window.location.href ='https://login.salesforce.com/?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Fc.na14.visual.force.com%252Fapex%252FReportPrintOut%253Fid%253D';
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
</head>
</html>