我已经创建了一个示例程序,但是我无法获得预期的结果,因此我调试了我的应用程序。我想检查/打印URL并将数据发布到服务器。
这是我的网址:mydomain.com/RESTapi/Rest_LoginValidate.php
发布日期:用户名:' pop',UserPwd:' pop'
以下是我在Worklight中使用的代码段。
myRESTAdapter.xml
<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="myRESTAdapter"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>myRESTAdapter</displayName>
<description>myRESTAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>mydomain.com</domain>
<port>80</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
<!-- Following properties used by adapter's key manager for choosing specific certificate from key store
<sslCertificateAlias></sslCertificateAlias>
<sslCertificatePassword></sslCertificatePassword>
-->
</connectionPolicy>
</connectivity>
<procedure name="getGmapLatLng"/>
</wl:adapter>
myRESTAdapter-impl.js
function getGmapLatLng(UserName,UserPwd) {
var path = '/RESTapi/Rest_LoginValidate.php';
var input = {
method : 'post',
returnedContentType : 'application/json',
path : path,
parameters : {
UserName : 'UserName',
UserPwd : 'UserPwd'
}
};
return WL.Server.invokeHttp(input);
}
结果我得到了什么:
{
"UserLogin": {
"ADMIN_FLAG": null,
"ADMIN_FNAME": null,
"ADMIN_ID": null,
"ADMIN_LNAME": null,
"ADMIN_LOCID": null,
"ADMIN_LOCNAME": null,
"ADMIN_MAIL": null,
"ADMIN_SEC_TYPE": null,
"BS_NATURE": null,
"BS_NATURENAME": null,
"RESPONSE": "authentication failed"
},
"isSuccessful": true,
"responseHeaders": {
"Connection": "close",
"Content-Length": "236",
"Content-Type": "text\/html",
"Date": "Thu, 09 Apr 2015 09:25:00 GMT",
"Server": "Apache",
"X-Powered-By": "PleskLin"
},
"responseTime": 583,
"statusCode": 200,
"statusReason": "OK",
"totalTime": 590
}
我收到了结果,但我无法成功登录(获取身份验证失败),所以我想检查一下我是否正在传递正确的路径并发布数据,并想知道我为什么会收到失败的结果?
答案 0 :(得分:1)
根据聊天中的讨论,您需要更改
parameters : {
UserName : 'UserName',
UserPwd : 'UserPwd'
}
致:
parameters : {
UserName : UserName,
UserPwd : UserPwd
}