function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jkucerajkucera 

No Protocol Error for HttpRequest XML Get

I'm an integrations n00b and can't get a basic XML post to work as I've been receiving an error.  Is this an Apex error or a received error from the other site?

 

system.CalloutException: no protocol:

 

<?xml version="1.0" encoding="ISO-8859-1"?>
<serv:message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<header>
<securityContext>
<webExID>jkucera</webExID>
<password>Jdk47012</password>
<siteID>243585</siteID>
<partnerID>g0webx!</partnerID>
</securityContext>
</header>
<body>
<bodyContent xsi:type="java:com.webex.service.binding.meeting.LstsummaryMeeting"><listControl><maximumNum>5</maximumNum></listControl><order><orderBy>STARTTIME</orderBy></order></bodyContent>
</body>
</serv:message>

 

I'm trying to get the XML file from this URL, and I'm fairly confident in my login credentials:

 

https://apidemoeu.webex.com/WBXService/XMLService

 

 My Apex method that attempts the HttpRequest get:

 

 

public static void callWebEx(String[] args)
{
WebEx_Login__c wec=[Select Id, siteName__c, xmlURL__c, siteId__c, partnerId__c, webExId__c, password__c, xmlServerURL__c FROM WebEx_Login__c LIMIT 1];

String siteName = wec.siteName__c; // WebEx site name
String xmlURL = wec.xmlURL__c; // XML API URL
String siteID = wec.siteId__c; // Site ID
String partnerID = wec.partnerId__c; // Partner ID
String webExID = wec.webExId__c; // Host username
String password = wec.password__c; // Host password
String xmlServerURL = wec.xmlServerURL__c;

String reqXML = '<?xml version="1.0" encoding="ISO-8859-1"?>\r\n';
reqXML += '<serv:message xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"';
reqXML+='>\r\n';

reqXML += '<header>\r\n';
reqXML += '<securityContext>\r\n';
reqXML += '<webExID>' + webExID + '</webExID>\r\n';
reqXML += '<password>' + password + '</password>\r\n';
reqXML += '<siteID>' + siteID + '</siteID>\r\n';
reqXML += '<partnerID>' + partnerID + '</partnerID>\r\n';
reqXML += '</securityContext>\r\n';
reqXML += '</header>\r\n';
reqXML += '<body>\r\n';
reqXML += '<bodyContent xsi:type="java:com.webex.service.binding.meeting.LstsummaryMeeting">';
reqXML += '<listControl>';
reqXML += '<maximumNum>5</maximumNum>';
reqXML += '</listControl>';
reqXML += '<order>';
reqXML += '<orderBy>STARTTIME</orderBy>';
reqXML += '</order>';
reqXML += '</bodyContent>\r\n';
reqXML += '</body>\r\n';
reqXML += '</serv:message>\r\n';
system.debug('ReqXML: '+reqXML);

System.debug('XML Request POSTed to ' + xmlServerURL + '\n');
System.debug(reqXML+'\n');

Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(reqXML);
req.setMethod('GET');
try{
HttpResponse res = http.send(req);//point of failure
system.debug('Status: '+res.getStatus());
system.debug('Status_Code: '+res.getStatusCode());
system.debug('Body: '+res.getBody());

XmlStreamReader reader = res.getXmlStreamReader();

while(reader.hasNext()) {
System.debug('Event Type:' + reader.getEventType());
if (reader.getEventType() == XmlTag.START_ELEMENT) {
System.debug(reader.getLocalName());
}//if
reader.next();
}//while
}catch(system.CalloutException e){
system.debug('Response Callout Exception: '+e);
}//try

}

 

 

 

 

 

Message Edited by jkucera on 02-09-2010 09:01 PM
Best Answer chosen by Admin (Salesforce Developers) 
jkucerajkucera

Turns out this was an Apex error due to bad code on my part. I was setting the end point as the entire XML body instead of setting the end point as the server URL.

 

Bad code:

 

Http http = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint(reqXML); req.setMethod('GET');

 Fixed Code:

 

Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(xmlServerURL);
req.setBody(reqXML);
req.setMethod('POST');