Django使用Firefox RESTClient & Jersey拒绝POST,使用Chrome POSTMAN和curl

时间:2021-06-11 19:35:42

I don't know much about Django but I need to write a client that interacts with a Django REST service.

我不太了解Django,但是我需要编写一个与Django REST服务交互的客户机。

GET works for me in all 4 interfaces I've tried: Chrome POSTMAN, Firefox RESTClient, Jersey Client in Java, and curl.

在我尝试过的4个界面中,为我找到工作:Chrome POSTMAN, Firefox RESTClient, Jersey客户端Java,和curl。

POST gets rejected by Django with a 400 BAD REQUEST in Jersey and RESTClient, but not in the other two. Unfortunately the ultimate solution is to use Jersey so that's a big problem.

POST在Jersey和RESTClient被Django拒绝了400个错误请求,但在另外两个中没有。不幸的是,最终的解决方案是使用泽西岛,这是一个大问题。

I'm guessing at this point that it's the client encoding that Django doesn't like so I'm hoping someone out there can tell me the difference between POSTMAN and RESTClient? (I'm sending the data as "raw" json in POSTMAN)

我想这是Django不喜欢的客户端编码我希望有人能告诉我POSTMAN和RESTClient之间的区别?(我将数据作为“原始”的json发送给邮递员)

Here's my jersey code:

这是我的球衣代码:

Client client = Client.create();
WebResource resource = client.resource("rest service endpoint");
resource.header("Content-Type", "application/json");
resource.post("{"\name\":\"test\",\"age\":29}");  // Returns a 400 Bad request

Posting {"name":"test","age":29} to Chrome works.

发布{“名称”:“测试”,“年龄”:29}到Chrome工作。

Thanks for the help.

谢谢你的帮助。

1 个解决方案

#1


1  

Ok, I figured it out from Jersey at least. Doing a tcpdump revealed that my application/json header wasn't making it through so I got that sorted out by doing ...

好吧,至少我是从新泽西来的。tcpdump显示我的应用程序/json头没有通过,所以我通过…

WebResource.Builder resource = client.resource("web server").type(MediaType.APPLICATION_JSON);

Then it worked. Still no idea why this doesn't work in REST Client so if someone knows that let me know!

那么它工作。仍然不知道为什么这个在REST客户端不起作用,所以如果有人知道的话,让我知道!

#1


1  

Ok, I figured it out from Jersey at least. Doing a tcpdump revealed that my application/json header wasn't making it through so I got that sorted out by doing ...

好吧,至少我是从新泽西来的。tcpdump显示我的应用程序/json头没有通过,所以我通过…

WebResource.Builder resource = client.resource("web server").type(MediaType.APPLICATION_JSON);

Then it worked. Still no idea why this doesn't work in REST Client so if someone knows that let me know!

那么它工作。仍然不知道为什么这个在REST客户端不起作用,所以如果有人知道的话,让我知道!