我是一个新手,正在编写一个SOAP web服务(用于集成目的),为了执行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){} 发布于 2013-08-01 02:39:33
我不熟悉您在这里使用的库,但我可以建议一些可能性进行研究:
Authorization头。这就是为什么你会在第二个请求中得到401。如果这是您第一次使用SOAP,那么您最好使用专用的SOAP库,而不是尝试自己构造请求。
发布于 2018-03-06 21:06:37
在第二个请求中,您没有包括身份验证,这就是为什么您会得到401 (未授权)错误。
在第一个请求中,看起来您的身份验证没有问题,但是服务器无法处理该请求。我想你没有提到你想要使用的IntegrationManagementService webservice的功能/操作。或者您正在使用需要启用MTOM的函数/操作。
https://stackoverflow.com/questions/16150900
复制相似问题