+ Start a Discussion

Calling an external webservices.

Hi all,
 I called an external webservices using visualforce with a button click but iam getting the following error.

System.CalloutException: Read timed out


Class.WebServ.SetbasicAuthCallout: line 30, column 20
External entry point 



<apex:page sidebar="false" controller="WebServ"> <apex:form > <h1>Synchronize Salesforce with MySQL </h1> <br/> <br/><b>Sync From Salesforce to MySQL</b> <br/> <br/> <apex:outputlink value="http://localhost/crm/accounts_mysql_tutorial.php"> Account</apex:outputlink> <apex:commandButton action= "{!SetbasicAuthCallout}" value="Account"/> <apex:outputText value="{!Details}"></apex:outputText> </apex:form> </apex:page>


public class WebServ { //The following example illustrates how you can use an authorization header with a request, and handle the response: public String getDetails() { // Get the XML document from the external server Http http = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint('http://localhost'); req.setMethod('GET'); HttpResponse res = http.send(req); // Log the XML content System.debug(res.getBody()); return res.getBody(); } public void SetbasicAuthCallout(){ HttpRequest req = new HttpRequest(); req.setEndpoint(''); req.setMethod('GET'); // Specify the required user name and password to access the endpoint // As well as the header and header information //String username = 'suganya_@gmail.com'; //String password = 'suganya'; //Blob headerValue = Blob.valueOf('username:password'); //String authorizationHeader = 'BASIC ' + //EncodingUtil.base64Encode(headerValue); //req.setHeader('Authorization', authorizationHeader); // Create a new http object to send the request object // A response object is generated as a result of the request Http http = new Http(); HTTPResponse res = http.send(req); System.debug(res.getBody()); } }


Plz guide me with the proceeding steps.Thanks in advance.

Message Edited by Nalini on 02-25-2009 03:38 AM

The error is stating that Apex made the callout request, but it timeout waiting for a response.

You can configure the timeout within the defined limits. Here is more info on setting the timeout. 


Also, is your webservice publicly available on the internet? The apex server makes the request and not your browser, so it needs to be publicly available. 

the 192.168 subnet is not publicly routable, you need to use a publicly accessible IP address and/or DNS name for your server, remember the salesforce.com server have to be able to reach it over the internet.