查看 API 文档,在我看来,他们期望这些字段是表单值。这是此处文档的摘录:
HTTP 方法
所有请求都通过使用 UTF-8 编码和 URL 编码值的 HTTP POST 或 GET 方法提交。
Expected "Content-Type" for POST is "application/x-www-form-urlencoded", however we also support "application/json", "application/jsonrequest", "application/x-javascript", "text/json", "text/javascript", "text/x-javascript", "text/x-json" when posting parameters as a JSON object.
So try changing your code to the following:
<cfhttp url="https://rest.nexmo.com/number/buy/" method="post" charset="utf-8">
<cfhttpparam name="Content-Type" value="application/x-www-form-urlencoded" type="header">
<cfhttpparam name="Accept" value="application/xml" type="header">
<cfhttpparam name="api_key" value="#api.key#" type="formField">
<cfhttpparam name="api_secret" value="#api.secret#" type="formField">
<cfhttpparam name="country" value="US" type="formField">
<cfhttpparam name="msisdn" value="11234567890" type="formField">
</cfhttp>
Note that I have the Accept header set to application/xml
. According to the docs this could also be application/json
. Change that value depending on what you want.