HBlog
patch의 RequestBody 본문
get만 쓰다가 patch로 Request를 하려 하니,
ReqestBody가 말썽이었다....
우선 OkHttpClient 라이브러리를 사용했기때문에,
그 형식에 맞춰 작성할 수밖에 없었는데...
https://trytoso.tistory.com/1344
이 블로그의 코드를 보면 Request부분에서 RequestBody를 생성하여 작업하는 것을 확인할 수 있다.
Request request = new Request.Builder()
.url(requestURL)
.patch(RequestBody.create(MediaType.parse("application/json"), jsonMessage))
.build();
이 때
https://square.github.io/okhttp/3.x/okhttp/okhttp3/RequestBody.html
RequestBody레퍼런스에는 RequestBody.create(MediaType contentType, String content)의 형식으로 쓰라고 되어 있었는데, 그렇게 작성하니 에러가 발생해서
→ RequestBody.create(String content, MediaType contentType) 식으로 변경했다.
'프로그래밍 기록 > Java' 카테고리의 다른 글
ZonedDateTime.parse() (0) | 2022.12.17 |
---|---|
ZonedDateTime Class (0) | 2022.12.17 |
3/16 Gson 라이브러리 (0) | 2022.12.17 |
Logger 선언문 (0) | 2022.12.17 |
3/3 자바강의 (0) | 2022.12.17 |
Comments