下图显示错误和cfdump
输出
这是我的JSON响应:
{
"properties": [{
"property": "email",
"value": "testingapis@hubspot.com"
}, {
"property": "firstname",
"value": "Adrian"
}, {
"property": "lastname",
"value": "Mott"
}, {
"property": "website",
"value": "http://hubspot.com"
}, {
"property": "company",
"value": "HubSpot"
}, {
"property": "phone",
"value": "555-122-2323"
}, {
"property": "address",
"value": "25 First Street"
}, {
"property": "city",
"value": "Cambridge"
}, {
"property": "state",
"value": "MA"
}, {
"property": "zip",
"value": "02139"
}]
}
这是我正在使用的代码。我使用cfset
设置值,然后使用cfhttp
,
<cfset stFields='{
{
"properties": [
{
"property": "email",
"value": "testingapis@hubspot.com"
},
{
"property": "firstname",
"value": "Adrian"
},
{
"property": "lastname",
"value": "Mott"
},
{
"property": "website",
"value": "http://hubspot.com"
},
{
"property": "company",
"value": "HubSpot"
},
{
"property": "phone",
"value": "555-122-2323"
},
{
"property": "address",
"value": "25 First Street"
},
{
"property": "city",
"value": "Cambridge"
},
{
"property": "state",
"value": "MA"
},
{
"property": "zip",
"value": "02139"
}
]
}
}'>
<cfhttp url="https://api.hubapi.com/contacts/v1/contact/?hapikey=demo" method="post" result="httpResp" timeout="60">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="body" value="#serializeJSON(stFields)#">
</cfhttp>
<cfdump var="#httpResp#" label="HTTP response">
转储后,会显示错误400 Bad request Access
请帮我纠正这个错误。
答案 0 :(得分:0)
创建结构而不是字符串。使用CFDump查看它是否正确。像这样:
<cfset stFields = {
"properties": [
{
"property": "email",
"value": "testingapis@hubspot.com"
},
{
"property": "firstname",
"value": "Adrian"
},
{
"property": "lastname",
"value": "Mott"
},
{
"property": "website",
"value": "http://hubspot.com"
},
{
"property": "company",
"value": "HubSpot"
},
{
"property": "phone",
"value": "555-122-2323"
},
{
"property": "address",
"value": "25 First Street"
},
{
"property": "city",
"value": "Cambridge"
},
{
"property": "state",
"value": "MA"
},
{
"property": "zip",
"value": "02139"
}
]
}>
<cfdump var="#stfields#">
然后在cfhttp中使用该结构的序列化版本。您也可以将其作为测试进行CFDump。
<cfdump var="#serializeJSON(stfields)#">