Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ibm mobilefirst MobileFirst平台JavaScript适配器可以';无法通过WLResourceRequest获取参数_Ibm Mobilefirst_Mobilefirst Adapters - Fatal编程技术网

Ibm mobilefirst MobileFirst平台JavaScript适配器可以';无法通过WLResourceRequest获取参数

Ibm mobilefirst MobileFirst平台JavaScript适配器可以';无法通过WLResourceRequest获取参数,ibm-mobilefirst,mobilefirst-adapters,Ibm Mobilefirst,Mobilefirst Adapters,我使用的是mobilefirst平台v7,我使用WLResourceRequest/sendFormParameters api发送post请求,但是,我无法从js适配器端获取提交的参数 下面是示例代码: var resourceRequest = new WLResourceRequest("adapters/businessAdapter/flightsearch", WLResourceRequest.POST); var params={ "flightNum":'mu8

我使用的是mobilefirst平台v7,我使用WLResourceRequest/sendFormParameters api发送post请求,但是,我无法从js适配器端获取提交的参数

下面是示例代码:

var resourceRequest = new WLResourceRequest("adapters/businessAdapter/flightsearch", WLResourceRequest.POST);
var params={
        "flightNum":'mu8899',
        "departCity":'SHA',
        "destCity" :'PEK'
};
resourceRequest.sendFormParameters(params).then(
        callSuccess,
        callFailure
);
js适配器代码:

function flightsearch(params) {
   WL.Logger.info("get params "+params);


    var input = {
        method : 'post',
        returnedContentType : 'json',
        path : 'restapi/api/flightsearch',
        body :{
            contentType: 'application/json; charset=utf-8',
            content:params
        },
        headers: {"Accept":"application\/json"} 
    };

    return WL.Server.invokeHttp(input);
}

您使用的语法适用于Java适配器

但是,对于JavaScript适配器,过程参数的处理方式不同

首先,您的适配器过程应定义所需的参数:

function flightsearch(flightNum, departCity, destCity) {
///
}
其次,此过程将使用HTTP
GET
POST
触发,其中包含一个名为
params
的参数,该参数需要包含一个数组,以正确的顺序表示所有过程参数:

params:["mu8899","SHA","PEK"]
现在使用JavaScript,这将转化为:

var resourceRequest = new WLResourceRequest("adapters/businessAdapter/flightsearch", WLResourceRequest.POST);
var params=[
        'mu8899',
        'SHA',
        'PEK'
];
var newParams = {'params' : JSON.stringify(params)};
resourceRequest.sendFormParameters(newParams).then(
        callSuccess,
        callFailure
);
如您所见,我们首先以正确的顺序构建JSON数组(注意,数组非对象),然后将其转换为字符串并使用参数名“
params
”将其发送到适配器