Related to this other question Discover Schema of Source + Metadata XML formats I am trying to download the Metadata API WSDL file from the Orgs URL https://ServInstance.salesforce.com/services/wsdl/metadata using this simple Apex code:
public Dom.Document mdApiWsdl() {
HttpRequest request = new HttpRequest();
request.setEndpoint(URL.getOrgDomainUrl().toExternalForm() + '/services/wsdl/metadata');
request.setMethod('GET');
request.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
request.setHeader('Content-Type', 'application/xml');
HttpResponse response = new Http().send(reqquest);
return response.getBodyDocument();
}
The issue I face is that the page is not a WSDL XML document but a strange HTML page simulating it. In a browser, it's possible to download the file as XML but in Apex code I couldn't find a way.
Why is Salesforce preventing us from downloading this single WSDL?
XmlStreamReader
?