1. java.lang.IllegalArgumentException: Expected URL scheme 'http' or 'https' but no colon was found
java.lang.IllegalArgumentException: Expected URL scheme 'http' or 'https' but no colon was found
at okhttp3.HttpUrl$Builder.parse$okhttp(HttpUrl.kt:1260) ~[okhttp-4.9.1.jar:na]
at okhttp3.HttpUrl$Companion.get(HttpUrl.kt:1633) ~[okhttp-4.9.1.jar:na]
at okhttp3.Request$Builder.url(Request.kt:184) ~[okhttp-4.9.1.jar:na]
...
해결시도 1.
jsonObjects.add("\"b_no\": \"0000000000\",");
jsonObjects.add("\"start_dt\": \"20000101\",");
jsonObjects.add("\"p_nm\": \"홍길동\",");
jsonObjects.add("\"p_nm2\": \"홍길동\",");
jsonObjects.add("\"b_nm\": \"(주)테스트\",");
jsonObjects.add("\"corp_no\": \"0000000000000\",");
jsonObjects.add("\"b_sector\": \"\",");
jsonObjects.add("\"b_type\": \"\"");
디버깅 찍어보니 내 jsonObject에 , 가 여러개 붙어있더라.
그래서 jsonObject에 들어있는 , 를 지워서 다시 해봤다.
그래도 같은 오류가 나왔다.
실패!
해결시도 2.
Reqeust.Builder()
할 때 코드를 url을 안넣었다.(...)
넣으니까 된다...
해결!
2. {"status_code":"BAD_JSON_REQUEST"}
POST할 때 보낸 Body가 잘못됐나보다.
이런 형태로 입력됐는데, "
를 처리하기위한 백슬래시\\
가 문제였다.
List<JSONObject>
형태로 담았는데, 문제 해결을 위해서 "가 안들어가는 Map<String, Object>
형식을 사용해 JSONObject
에 값을 넣어줬다.
Map<String, Object> map = new LinkedHashMap<>();
map.put("b_no", "0000000000");
map.put("start_dt", "20000101");
map.put("p_nm", "홍길동");
map.put("p_nm2", "홍길동");
map.put("b_nm", "(주)테스트");
map.put("corp_no", "0000000000000");
map.put("b_sector", "");
map.put("b_type", "");
JSONArray jsonArray = new JSONArray();
jsonArray.add(map);
JSONObject jsonObject= new JSONObject();;
jsonObject.put("businesses", jsonArray);
여기서 LinkedHashMap
을 사용했는데, Map
의 경우 데이터의 저장에 순서가 없어서 JSONObject
에 값 입력시 값을 섞어서 가져온다.
{
"business":[
{
"p_nm":"홍길동",
"start_dt":"20000101",
"b_no":"0000000000",
"p_nm2":"홍길동",
"b_nm":"(주)테스트",
"corp_no":"0000000000000",
"b_sector":"",
"b_type":""
}
]
}
위와 같이 데이터를 가져와서 Map
에 저장할 때 입력 순서대로 저장하는 LinkedHashMap
을 사용해 저장했다.
그러면 JSONObject에 입력해도 내가 Map
에 데이터를 저장한 순서대로 들어가게 된다.
{
"businesses": [
{
"b_no": "0000000000",
"start_dt": "20000101",
"p_nm": "홍길동",
"p_nm2": "홍길동",
"b_nm": "(주)테스트",
"corp_no": "0000000000000",
"b_sector": "",
"b_type": ""
}
]
}
문제 해결!
'SpringBoot > Error' 카테고리의 다른 글
java.sql.SQLException: Access denied for user 'nobody'@'172.17.0.1' (using password: YES) 에러 (1) | 2023.03.28 |
---|---|
JpaAuditing - extends BaseEntity 적용 안됨 (0) | 2022.12.22 |
application.yml 없을 시 도커 컨테이너 내려감 (0) | 2022.12.21 |
Inferred type 'S' for type parameter 'S' is not within its bound; should extend (1) | 2022.12.20 |