首页 > 解决方案 > 奇怪的 ColdFusion cfscript 语法问题

问题描述

我的 cfscript 中有一个非常奇怪的语法错误。

stFields = {
    "EligibilityQuery": { 
        "Patient": {
            "FirstName": arguments.data.lname, 
            "MiddleName": "", 
            "LastName": arguments.data.fname, 
            "DateOfBirth": dateformat(arguments.data.dob,'yyyy-mm-dd'), 
            "Gender": arguments.data.gender,
            "SSN": arguments.data.SSN,
            "Address": {
                "FirstLine": "", 
                "SecondLine": "",
                "ZipCode": arguments.data.ZipCode
            } 
        },
        "NPI": "1111111" 
    }
};

// call API
var authorization = "Basic: " & ToBase64('username:password');
cfhttp(method="POST", url="https://mysite/api/myAPI/", result="apiResult"){
    cfhttpparam(name="Authorization", type="header", value="#authorization#");
    cfhttpparam(name="Content-Type", type="header", value="application/json");
    cfhttpparam(type="body", value="#serializeJSON(stFields)#");
}
apiResult = deserializeJSON(apiResult.fileContent);

它在 cfhttp 上返回错误(脚本语句必须以“;”结尾。)

错误 - CFML 编译器正在处理:

cfhttp(method="POST", url="https://mysite/api/myAPI/", result="apiResult")

我在哪里错过了“;”?

标签: coldfusion

解决方案


期待;之后cfhttp(method="POST", url="https://mysite/api/myAPI/", result="apiResult")

你是CF9还是CF10?尝试这个:

// call API
var authorization = "Basic: " & ToBase64('username:password');

httpService = new http(method = "POST", charset = "utf-8", url = "https://mysite/api/myAPI/");

httpService.addParam(name = "Authorization", type = "header", value = "#authorization#");
httpService.addParam(name = "Content-Type", type = "header", value = "application/json");
httpService.addParam(type = "body", value = "#serializeJSON(stFields)#");

apiResult = httpService.send().getPrefix();
apiResult = deserializeJSON(apiResult.fileContent);

推荐阅读