我想从mobilefirst 8.0 Javascript Adapter调用一个RESTful web服务,但问题是当我从Javascript Adapter调用它时它失败但是当我从Java Adapter调用相同的服务时它成功执行了。以下是代码:
JS适配器代码(不工作)
function addStatus(requestData){
var input = {
method : 'put',
returnedContentType : "application/json;charset=UTF-8",
path : "cli/version/addStatus?version=1&status=APPROVED&UCD_SESSION_KEY=1",
headers: {
"Authorization":"Basic " + requestData.authHeader,
"Accept" : "application/json",
"Content-type": "application/json",
"Connection", "keep-alive"
}
};
var response = WL.Server.invokeHttp(input);
return response;
}
在回复中,我的状态代码为302 。
Java适配器代码(工作)
String pageUrl ="https://my.server.url:port/cli/version/addStatus?version=1&status=APPROVED&UCD_SESSION_KEY=1";
String username = "username";
String password = "password";
HttpClient httpClient = new DefaultHttpClient();
HttpPut httpGet = new HttpPut(pageUrl);
String credential = Base64.getEncoder().encodeToString((username+":"+password).getBytes());
httpGet.setHeader("Authorization", "Basic " + credential);
httpGet.setHeader("Accept", "application/json");
httpGet.setHeader("Connection", "keep-alive");
httpGet.setHeader("Content-type", "application/json");
HttpResponse httpResponse = httpClient.execute(httpGet);
我没有收到任何错误,我可以看到此服务所做的更改。 AM我在JS Adapter中输入输入时遗漏了什么?