看看API文档,我觉得他们期望字段是表单值。下面是从the documentation here的摘录:
HTTP方法
所有请求通过HTTP POST提交或使用UTF-8编码和URL编码值GET方法。
POST的预期“Content-Type”是“application/x-www-form-urlencoded”,但是我们也支持“application/json”,“application/jsonrequest”,“application/x-javascript” ,“text/json”,“text/javascript”,“text/x-javascript”,“text/x-json”作为JSON对象发布参数时。
所以试着改变你的代码如下:
<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>
请注意,我有接受头设置为application/xml
。根据文件,这也可能是application/json
。根据你想要的改变这个值。
你的代码对我来说是正确的。它是否认识到你所要求的isdn是无效的? – BKK 2013-03-21 19:22:34
@BenKoshy我已经检查过所有传递的内容都是有效的。在发布之前,我只是更改了号码。 – Dre 2013-03-21 19:45:59