I am a newbie and am writing a SOAP web service (for integration purpose), in order to execute the SOAP call I need to authenticate the user first(standard integration user).
Following is the code snippet for it. However, when I execute the callout, it throws error code 500 for Basic Http request and error code 401 for the second Http request.
Is this the correct approach?
HTTP auth = new HTTP();
HTTPRequest r = new HTTPRequest();
r.setEndpoint('https://domainname.net/enterprise/soap?ServiceName=IntegrationManagementService');
Blob headerValue = Blob.valueOf(username+':'+password);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
r.setHeader('Authorization', authorizationHeader);
r.setMethod('POST');
try
{
HTTPResponse authresp = auth.send(r);
if(authresp.getStatusCode() == 200)
{
system.debug('Authentication success!!!' + authresp);
}
else
{system.debug('Authentication failed!!!' + authresp + authresp.getStatusCode());}
}catch(exception e){}
//construct http request
string endpointURL = 'https://doaminname.net/enterprise/soap?ServiceName=IntegrationManagementService';
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint(endpointURL);
req.setHeader('Content-Type','application/xml');
req.setBody(TaleoXML);
//send http request
Http http = new Http();
try
{
HttpResponse res = http.send(req);
//check the response
if(res.getStatusCode() == 200)
{
system.debug('Callout success!!!' + res);
}
else
{system.debug('Callout failed!!!' + res + res.getStatusCode());}
}catch(exception e){}