POST request on Jetty Client 9.X

Asked

Viewed 51 times

6

I’m using the Jetty Client to request a API Web, until recently everything was ok, but I felt the need to send data via POST.

Problem
In the documentation of Jetty says that POST request data should be passed by the method param("chave", "valor"), however the data is being passed via query-string

Request r = client.POST(url).param("access_token", accessToken);

The request is being in this format:
api.web.com/? access_token=1727020009.2da29da.ed9bdd6cc095430e8f1640bbeeas

I also checked the message by wireshark inserir a descrição da imagem aqui

Has anyone ever come across this problem?

  • How do you know that it is formatting this value?

  • I used System.out.print

  • 1

    But did you ever run the request and check on the network whether it is being sent as a query string or not? Because this can be formatting when showing

  • I just auditioned with the wireshark, and edited the question.

  • Give a system out in its variable "url" and show how it is

  • "http://api.instagram.com/"

  • In your image was added "/v1/users/self/feed", it can be the redirect that is done automatically by Jetty, Instagram itself redirects you and plays for querystring. Try it on another site.

  • no no, it was that I tried to omit the url at the beginning of the question.... but the url is correct

  • Like I said, you tried it on another site to see if I persisted?

Show 4 more comments

1 answer

0


So, the documentation of Jetty until today is incorrect, I followed the same logic that the Jersey implements, the data via POST, must be encapsulated in a formulário.

In Jetty the Post data pass is as follows:

Request r = client.newRequest("http://localhost")
.method(HttpMethod.POST)
.path("/post.php?as=a")
.param("access_token", accessToken);
Fields fields = new Fields();
fields.add("post1", "valorpost1");
FormContentProvider content = new FormContentProvider(fields);
r.content(content);
r.send()

That has as the return:

[POST] => Array
    (
        [asd] => asdasd
    )

[GET] => Array
    (
        [access_token] => asdasdasdsd
    )

This was noticed when I entered the api doc and found that the method param in Request it is not to override data POST and yes GET as is said in other documents

API DOC

Below we have the Jetty documentation stating that the post should be passed via param

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.