3
我正在做一個任務,我需要與Tastypie API進行交互。我無法控制API,我只是給了它的細節,並告訴它設置爲允許GET,POST和DELETE的唯一。Django - Tastypie POST(更新)導致409衝突
例POST - 工程
curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"email":"[email protected]","tr_referral":"SomeFeed","mailing_lists":1,"ip_address":"192.168.1.23"}' http://api.somesite.info/v1/account/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94
範例中得到 - 工程
curl http://api.somesite.info/v1/account/202126/?username=test\&api_key=a0495db44f4gch749c4gf56906350f336571d94
GET響應:
{"birth_date": null, "city": "", "country": "nl", "email": "[email protected]", "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": ""}
現在,這裏是我爲了試圖觸發的許多後的一個更新記錄:
curl --dump-header - -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"email":"[email protected]","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 [email protected] already exists.
我也試過張貼到以下網址:
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密鑰等
PUT命令呢? –