我正在尝试使用CFHttp来发布到Nexmo API。
<cfhttp url="https://rest.nexmo.com/number/buy/" method="post">
<cfhttpparam name="api_key" value="#api.key#" type="url">
<cfhttpparam name="api_secret" value="#api.secret#" type="url">
<cfhttpparam name="country" value="US" type="url">
<cfhttpparam name="msisdn" value="11234567890" type="url">
</cfhttp>运行此命令时,我得到状态420 (参数错误)。
我做错了什么?
下面是一个用PHP编写的例子:API
发布于 2013-03-22 03:19:20
查看API文档,在我看来,他们期望字段是表单值。以下是the documentation here的摘录
HTTP方法
所有请求都是使用UTF-8编码和URL编码值通过HTTP POST或GET方法提交的。
对于POST,我们期望的"Content-Type“是"application/x-www-form-urlencoded",,但是我们也支持”/ JSON“,"application/jsonrequest","application/x-javascript","text/json","text/javascript","text/x-javascript","text/x-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>请注意,我将Accept标头设置为application/xml。根据文档,这也可能是application/json。根据需要更改该值。
发布于 2013-03-22 03:18:41
尝试更改为formfield
<cfhttp url="https://rest.nexmo.com/number/buy/" method="post">
<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>这篇文档正在寻找一个帖子,而你正在发送一个组合的post/get。根据您发送的内容,您不会发送变量。FormField会解决这个问题。
https://stackoverflow.com/questions/15555921
复制相似问题