简体   繁体   中英

Sending raw data in request body

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM