Send request with parameter IBM Worklight

2019-08-28 03:09发布

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条回答
beautiful°
2楼-- · 2019-08-28 03:50

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);
}
查看更多
登录 后发表回答