Sending raw data in request body

1.7k Views Asked by At

I'm facing the problem with sending request body as raw text without quotes.

The content type of request should be text/uri-list.

Sending it in Postman works correctly but when I try to implement the same operation in java it does not work.

I'm using feign as api client.

Client definition of endpoint looks like this

@RequestLine("PUT /someEndpointOne/{id}/someEndpointTwo")
@Headers("Content-Type: text/uri-list")
JSONObject addSomethingToSomething(@Param("id") String id, @RequestBody okhttp3.RequestBody uri); 

And I use it in test like this:

somethingClient.addSomethingToSomething("1", okhttp3.RequestBody.create(okhttp3.MediaType.parse("text/uri-list"), "http://localhost/someEndpointTwo/1"))

Instead of sending raw data it actually sends empty object:

PUT http://localhost/someEndpointOne/1/someEndpointTwo HTTP/1.1

Content-Type: text/uri-list

Content-Length: 2

{}

END HTTP (2-byte body)

what causes bad respone.

I would be grateful for help with solving this problem.

1

There are 1 best solutions below

0
asherbret On

The following works for me:

@PutMapping(path = "/someEndpointOne/{id}/someEndpointTwo", headers = "Content-Type=text/uri-list")
JSONObject addSomethingToSomething(@PathVariable("id") String id, @RequestBody okhttp3.RequestBody uri); 

Where @PutMapping comes from org.springframework.web.bind.annotation.PutMapping and @PathVariable comes from org.springframework.web.bind.annotation.PathVariable.