Send request with parameter IBM Worklight

依然范特西╮ 提交于 2020-01-16 18:06:35

问题


I've already use http adapter and successfully send a request

but I can't do it with parameter

I want to send the parameter cmd=login

how to put it in parameter = [] ?

var invocationData = {
        adapter : 'RSSReader',
        procedure : 'login',
        parameters :[]
    };

----------------------update-------------------------------

I try the official parameter format

var invocationData = {
        adapter : 'HTTPAdapter',
        procedure : 'login',
        parameters :[{name : 'cmd', value : 'login'}]
    };

but still send nothing?

<?xml version="1.0" encoding="UTF-8"?>
<displayName>HTTPAdapter</displayName>
<description>HTTPAdapter</description>
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol>http</protocol>
        <domain>my-ip-address</domain>
        <port>80</port> 
        <!-- Following properties used by adapter's key manager for choosing specific certificate from key store  
        <sslCertificateAlias></sslCertificateAlias> 
        <sslCertificatePassword></sslCertificatePassword>
        -->     
    </connectionPolicy>
    <loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>

<procedure name="login"/>

and this is the adapter impl

function login() {

var input = {
    method : 'post',
    returnedContentType : 'json',
    path : '/sp/api/'
};

return WL.Server.invokeHttp(input);}

回答1:


Take a look at the examples provided in a newly creatd HTTP adapter in the -impl.js file.
You can do this like so:

Client JavaScript

var invocationData = {
    adapter : 'myAdapter',
    procedure : 'myProcedure',
    parameters :['cmd=login']
};
...
...

Adapter XML

...
...
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
    <protocol>http</protocol>
    <domain>www.example.com</domain>
    <port>80</port> 
</connectionPolicy>

Adapter JavaScript

function myProcedure(myParameter) {
    path = getPath(myParameter);

    var input = {
        method : 'get',
        returnedContentType : 'xml',
        path : path
    };

    return WL.Server.invokeHttp(input);
}

function getPath(myParameter) {
    return ("?" + myParameter);
}


来源:https://stackoverflow.com/questions/25600168/send-request-with-parameter-ibm-worklight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!