I am writing a web service for which sends a SOAP payload as its body. In order to access the 3rd party server, I need an authenticated user. I am using Basic Http authentication for that purpose. Following is the code snippet.
HTTP auth = new HTTP();
HTTPRequest r = new HTTPRequest();
string endpointurl='https://domainname.net/enterprise/soap?ServiceName';
r.setEndpoint(endpointurl);
Blob headerValue = Blob.valueOf(username +':' +password);
String authorizationHeader = 'Basic ' + 'EncodingUtil.base64Encode(headerValue);
//String authorizationHeader = username+':'+password;
system.debug('Encoder Value' + EncodingUtil.base64Encode(headerValue));
r.setHeader('Authorization', authorizationHeader);
r.setHeader('SOAPAction', 'http://www.domainname.com/ws/integration/toolkit/2011/05/management#submitDocument');
r.setMethod('POST');
Following code will post the http request.
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){}
When I post the request, it is giving an http 500 internal server error. Is the format of sending http request correct? Am I missing some parameters?
Content-Type
and POST body looking like?