如何在 mobilefirst 8.0 中使用 JavaScript 中的 Post 方法传递参数以在服务器上上传图像



我尝试通过post方法将图像发送到后端,因为get方法无法支持长uri。我不知道如何将参数传递给适配器。我首先使用 mfp7.1 移动成功传递参数,但对于移动优先 8.0,我需要使用不同的方法,即 post 方法。有人可以向我解释一下吗

    var invocationData = {
    LOCALE: locale,
    CHANNEL: channel,
    CLIENT_OS: os,
    TYPE: type,
    ISSUE_TYPE: issueType,
    STATION: type === 'GENERAL_INQUIRY' ? '' : station,
    CATEGORY: type === 'GENERAL_INQUIRY' ? station : '',
    DESCRIPTION: desc,
    LOCATION: loc,
    CONTRACT_ACC_NO: accNo,
    PHOTOS: photo
  };
  var resourceRequest = new WLResourceRequest(
    '/adapters/Report/makeReport',
    WLResourceRequest.POST
  );
 request.sendFormParameters(invocationData).then(
function(response) {
    // success flow
},
function(error) {
    // fail flow
}
);

Javascript 适配器

function invokeBackend(args, proc){
WL.Logger.info("Invoking Backend procedure " + proc);
WL.Logger.info(args);
var path = "SEB-Middleware/api/" + proc;
var input = {
        method : 'post',
        returnedContentType : 'json',
        path : path,
        body : {
            contentType:"application/json; charset=UTF-8",
            content: JSON.stringify(args)
        }
    };
var response = WL.Server.invokeHttp(input);
if(response &&
        (response['isSuccessful'] && response.isSuccessful) && 
        (response['statusCode'] && response.statusCode == 200)){
    return response;
}else{
    WL.Logger.warn("Invocation Error: " + proc);
    var locale = 'en';
    if(args && args['LOCALE']) locale = args.LOCALE;
    var resp = null;
    if(response['statusCode']){
        resp =  com.seb.mfp.utility.ResponseUtil.getErrorResponse(response.statusCode, locale);
    }else{
        resp = com.seb.mfp.utility.ResponseUtil.getErrorResponse(locale);
    }
    WL.Logger.warn(resp);
    return resp;
}
 }

我收到无法从控制台读取未定义的属性"发送表单参数"。如何使用我当前的 json 传递参数

您提到错误消息是:

Cannot read property 'sendFormParameters' of undefined 

我在你的代码中看到了这一点:

var resourceRequest = new WLResourceRequest(
    '/adapters/Report/makeReport',
    WLResourceRequest.POST
  );
 request.sendFormParameters(invocationData).then(

这需要更正为:

var resourceRequest = new WLResourceRequest(
    '/adapters/Report/makeReport',
    WLResourceRequest.POST
  );
 resourceRequest.sendFormParameters(invocationData).then(

相关内容

  • 没有找到相关文章

最新更新