适配器JS
function getCitiesByCountry(countryName)
{
var request =
var request=
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
<soapenv:Header/>
<soapenv:Body>
<web:GetCitiesByCountry>
<!--Optional:-->
<web:CountryName>INDIA</web:CountryName>
</web:GetCitiesByCountry>
</soapenv:Body>
</soapenv:Envelope>;
var input =
{
method: 'post',
returnedContentType: 'xml',
path: '/globalweather.asmx',
body: {
content: request.toString(),
contentType: 'text/json; charset=utf-8'
}
};
var result = MFP.Server.invokeHttp(input);
return result.Envelope.Body;
};
适配器XML
<displayName>JavaScriptSOAP</displayName>
<description>JavaScriptSOAP</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>www.webservicex.net</domain>
<port>80</port>
</connectionPolicy>
</connectivity>
<procedure name="getCitiesByCountry" secured ="false"/>
Index.js
function submitRequest()
{
var resourceRequest = new WLResourceRequest("adapters/JavaScriptSOAP/getCitiesByCountry", WLResourceRequest.POST);
resourceRequest.setQueryParameter("params", "['India']");
resourceRequest.send().then(
function(response) {
alert('response '+JSON.stringify(response.responseText));
},
function(response) {
alert("HTTP Failure "+JSON.stringify(response));
}
);
}
我需要将参数传递给http Adapters.It包含Country Name。我已经在Index js文件中包含了国家名称。在预览应用程序时,我收到错误代码415,
在我收到的控制台中
[AUDIT ] CWWKS1100A: Authentication did not succeed for user ID test. An invalid user ID or password was specified.
[AUDIT ] CWWKS1100A: Authentication did not succeed for user ID test. An invalid user ID or password was specified.
[AUDIT ] CWWKS1100A: Authentication did not succeed for user ID test. An invalid user ID or password was specified.
我有:
面向Web开发人员的Eclipse Java EE IDE。 版本:Mars.2发布(4.5.2) 构建ID:20160218-0600 Windows 7
我必须提供什么身份验证。如何克服错误?
答案 0 :(得分:1)
A 415是&#34;不支持的媒体类型&#34;。这意味着服务器确定您发送的请求不包含服务器认为应该的数据类型。
你得到这个的原因是因为你发送的POST请求没有正文和查询参数。您可以采取的措施是将POST请求更改为GET请求。只需改变
WLResourceRequest("adapters/JavaScriptSOAP/getCitiesByCountry", WLResourceRequest.POST);
到
WLResourceRequest("adapters/JavaScriptSOAP/getCitiesByCountry", WLResourceRequest.GET);
答案 1 :(得分:0)
您传递的参数不正确。 params
是一个数组,因此您的代码应该看起来像
function submitRequest() { var resourceRequest = new WLResourceRequest("adapters/JavaScriptSOAP/getCitiesByCountry", WLResourceRequest.POST); resourceRequest.setQueryParameter("params", "['India']"); resourceRequest.send().then( function(response) { alert('response '+JSON.stringify(response.responseText)); }, function(response) { alert("HTTP Failure "+JSON.stringify(response)); } ); }
答案 2 :(得分:0)
尝试将secured =“false”添加到XML文件中的过程声明:
<procedure name="getCitiesByCountry" secured="false"/>