我是新手,正在編寫SOAP Web服務(用於集成目的),以便執行我需要首先驗證用戶(標準集成用戶)的SOAP調用。從Salesforce到Taleo的基本HTTP認證
以下是它的代碼片段。但是,當我執行標註時,它會針對基本Http請求引發錯誤代碼500,併爲第二個Http請求引發錯誤代碼401。
這是正確的方法嗎?
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){}