gpt4 book ai didi

javascript - 如何为工作海报 REST 调用定义 MFP javascript 适配器?

转载 作者:行者123 更新时间:2023-11-27 22:56:24 27 4
gpt4 key购买 nike

我想编写一个与 Web 服务器通信的 MFP 适配器 (v8)。服务器等待包含图像信息的参数图像。移动客户端实现是在 ionic cordova 中实现的。

首先,我检查了海报,这是要发送的正确请求,但我无法找到适配器的正确配置/实现/调用。

我做错了什么?

1) 这是海报调用的工作副本

POST /GetImageKeywords HTTP/1.1
Host: XXXXXXX.mybluemix.net:443
Cache-Control: no-cache
Postman-Token: a98cac04-fe12-3e0f-2884-250bb5ff39ae
Content-Type: application/x-www-form-urlencoded

image=data%3..................

2) 这是不工作的 MFP 适配器实现:

function getTagsForPicture(urlimage) {
var input = {
method : 'post',
returnedContentType : 'xml',
path : 'GetImageKeywords',
parameters: {'image': urlimage },
headers: {"Accept":"application\/x-www-form-urlencoded",
"Content-Type":"application\/x-www-form-urlencoded"}
};
return MPF.Server.invokeHttp(input);
}

3) 这是移动客户端适配器调用:

var getTagsRequest = new WLResourceRequest(
"/adapters/UploadPic/getTagsForPicture",
WLResourceRequest.POST);

getTagsRequest.setQueryParameter("params", "['image']" );
getTagsRequest.send().then(
getTagsSuccess,
getTagsFailure
);

function getTagsSuccess (result){
console.log('Success, getTags is : ', result);
q.resolve(result);
WL.SimpleDialog.show(
"Got Tags", "You can continue using the application",
[{text: "OK, thanks", handler: function() {WL.Logger.debug("Got Tags"); }
}]
);
};

function getTagsFailure (result){
console.log('Failure, getTags is : ', result);
q.reject(result);
WL.SimpleDialog.show(
"Got NO Tags", "Try it again later.",
[{text: "OK, thanks", handler: function() {WL.Logger.debug("Got NO Tags"); }
}]
);
}
console.log("Tags*** ", q);
return q.promise;

chrome 中的日志信息

{responseHeaders: Object, status: 500, responseText: "{"errors":["Unexpected error in server, see logs"],"isSuccessful":false,"warnings":[],"info":[]}", responseJSON: Object, invocationContext: null}
invocationContext:null
responseHeaders:Object
responseJSON:Object
responseText
:"{"errors":["Unexpected error in server, see logs"],"isSuccessful":false,"warnings":[],"info":[]}"
status:500

登录 MFP 开发服务器:

Error   FWLST0904E: Exception was thrown while invoking procedure: getTagsForPicture in adapter: UploadPic
Date Wednesday, Jun 1, 2016, 9:27 PM
Server fe80:0:0:0:a65e:60ff:fedc:5a99%4
Security Level Error
Source Class com.ibm.mfp.server.js.adapter.internal.JavascriptManagerImpl
Source Method Name
Logger Name com.ibm.mfp.server.js.adapter.internal.JavascriptManagerImpl
Thread ID 1743
Message FWLST0904E: Exception was thrown while invoking procedure: getTagsForPicture in adapter: UploadPic

Config.xml信息:

<procedure name="getTagsForPicture" secured="false"/>
<procedure name="uploadVacationInformationComplete" secured="false"/>
<procedure name="unprotected" secured="false"/>

最佳答案

我有一个拼写错误MPF,我找到了配置的解决方案:

这是 javascript 适配器的工作实现:

function getTagsForPicture(urlimage) {
var value = "image=" + urlimage;
MFP.Logger.warn("Image input " + value.toString());
var requestStructure = {
method : 'post',
returnedContentType : 'xml',
path : 'GetImageKeywords',
parameters: {'image': urlimage },
headers: {"Accept":"application\/plain"}
};
MFP.Logger.warn("Preparing request structure " + JSON.stringify(requestStructure));
return MFP.Server.invokeHttp(requestStructure);
}

客户端内部出现与("params", "['image']")相关的错误,正确的是("params", [image])强>.

var getTagsRequest = new WLResourceRequest(
"/adapters/UploadPic/getTagsForPicture",
WLResourceRequest.POST);

getTagsRequest.setQueryParameter("params", [image] );
getTagsRequest.send().then(
getTagsSuccess,
getTagsFailure
);

function getTagsSuccess (result){
console.log('Success, getTags is : ', result);
q.resolve(result);
WL.SimpleDialog.show(
"Got Tags", "You can continue using the application",
[{text: "OK, thanks", handler: function() {WL.Logger.debug("Got Tags"); }
}]
);
};

function getTagsFailure (result){
console.log('Failure, getTags is : ', result);
q.reject(result);
WL.SimpleDialog.show(
"Got NO Tags", "Try it again later.",
[{text: "OK, thanks", handler: function() {WL.Logger.debug("Got NO Tags"); }
}]
);
}

关于javascript - 如何为工作海报 REST 调用定义 MFP javascript 适配器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37575118/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com