[英]Sending raw data in request body
我面臨着將請求正文作為不帶引號的原始文本發送的問題。
請求的內容類型應該是text/uri-list 。
在 Postman 中發送它可以正常工作,但是當我嘗試在 Java 中實現相同的操作時它不起作用。
我正在使用 feign 作為 api 客戶端。
端點的客戶端定義如下所示
@RequestLine("PUT /someEndpointOne/{id}/someEndpointTwo")
@Headers("Content-Type: text/uri-list")
JSONObject addSomethingToSomething(@Param("id") String id, @RequestBody okhttp3.RequestBody uri);
我在這樣的測試中使用它:
somethingClient.addSomethingToSomething("1", okhttp3.RequestBody.create(okhttp3.MediaType.parse("text/uri-list"), "http://localhost/someEndpointTwo/1"))
它實際上發送空對象而不是發送原始數據:
PUT http://localhost/someEndpointOne/1/someEndpointTwo HTTP/1.1
內容類型:text/uri-list
內容長度:2
{}
結束 HTTP(2 字節正文)
什么導致不良反應。
如果您能幫助我解決這個問題,我將不勝感激。
以下對我有用:
@PutMapping(path = "/someEndpointOne/{id}/someEndpointTwo", headers = "Content-Type=text/uri-list")
JSONObject addSomethingToSomething(@PathVariable("id") String id, @RequestBody okhttp3.RequestBody uri);
其中@PutMapping
來自org.springframework.web.bind.annotation.PutMapping
和@PathVariable
來自org.springframework.web.bind.annotation.PathVariable
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.