3

我正在做一个需要与 Tastypie API 交互的任务。我无法控制 API,我刚刚获得了它的详细信息,并告诉它设置为只允许 GET、POST 和 DELETE。

示例 POST - 有效

curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X     POST -d '{"email":"test@someemail.com","tr_referral":"SomeFeed","mailing_lists":1,"ip_address":"192.168.1.23"}' http://api.somesite.info/v1/account/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94

示例 GET - 有效

curl http://api.somesite.info/v1/account/202126/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94

获取响应:

{"birth_date": null, "city": "", "country": "nl", "email": "test@someemail.com", "first_name": "", "gender": "", "last_name": "", "lead": true, "mailing_lists": [{"name": "Classic NL", "resource_uri": "/v1/mailing_list/1/"}], "phone": "", "resource_uri": "/v1/account/202126/", "street_number": "", "tr_input_method": "", "tr_ip_address": "192.168.1.23", "tr_language": "", "tr_referral": {"name": "SomeFeed", "resource_uri": ""}, "utm_campaign": "", "utm_medium": "", "utm_source": "SomeFeed", "zipcode": ""}

现在这是我尝试过的许多 POST 之一,以触发记录的更新:

curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"email":"test@someemail.com","tr_referral":"SomeFeed","mailing_lists":2,"ip_address":"192.168.1.46"}' http://api.somesite.info/v1/account/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94

结果是:

HTTP/1.1 409 CONFLICT
Server: nginx/1.2.1
Date: Wed, 14 Nov 2012 20:42:35 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive

Email address test@someemail.com already exists.

我还尝试发布到以下 URL:

http://api.somesite.info/v1/account/202126/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94

那返回:

HTTP/1.1 501 NOT IMPLEMENTED
Server: nginx/1.2.1
Date: Wed, 14 Nov 2012 20:45:01 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive

我需要使用 POST 更新记录。我究竟做错了什么?

请注意,我已经更改了一些数据,例如 URL、api 密钥等

4

1 回答 1

2

我想我应该来提供一个“答案”。

事实证明,作业文件中的内容具有误导性,我不会通过 POST 更新帐户,因为不允许使用此功能。

他们真正想要的是让我删除该帐户,然后重新发布它,这似乎不是最好的方法,因为每次“更新”都需要两次 API 调用,而不仅仅是一个。甚至无法使用 PATCH 命令。

于 2012-11-17T00:59:18.953 回答