Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Salesforce到Taleo的基本HTTP身份验证_Http_Authentication_Soap_Apex Code_Taleo - Fatal编程技术网

从Salesforce到Taleo的基本HTTP身份验证

从Salesforce到Taleo的基本HTTP身份验证,http,authentication,soap,apex-code,taleo,Http,Authentication,Soap,Apex Code,Taleo,我是一个新手,正在编写一个soapweb服务(用于集成目的),为了执行SOAP调用,我需要首先对用户进行身份验证(标准集成用户) 下面是它的代码片段。但是,当我执行callout时,它会为基本Http请求抛出错误代码500,为第二个Http请求抛出错误代码401 这是正确的方法吗 HTTP auth = new HTTP(); HTTPRequest r = new HTTPRequest(); r.setEndpoint('https://domainname.net/enterprise/s

我是一个新手,正在编写一个soapweb服务(用于集成目的),为了执行SOAP调用,我需要首先对用户进行身份验证(标准集成用户)

下面是它的代码片段。但是,当我执行callout时,它会为基本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){}  

我不熟悉您在这里使用的库,但我可以提出一些调查的可能性:

  • 基本身份验证是一种无状态方法。您不登录,而是一直使用它登录。这意味着没有单独的初始身份验证请求(如代码所示);每个请求都包含
    授权
    标题。这就是为什么你在第二个请求中得到了批准

  • 在第一个请求中,您提供了凭据,服务器遇到了意外的内部错误(这就是原因)。若它包含一个带有错误响应的主体,那个么它可能包含更多信息。我猜这与你的帖子没有提供一个主体有关,而服务器也没有预料到这一点


如果这是您第一次使用SOAP,您最好使用专用的SOAP库,而不是自己构造请求。

在第二个请求中,您不包括身份验证,这就是为什么会出现401(未经授权)错误

在第一个请求中,您的身份验证似乎正常,但服务器无法处理该请求。我认为您没有提到要使用的IntegrationManagementService Web服务的功能/操作。或者您正在使用需要启用MTOM的功能/操作