When using the API, the parameter requested to the server does not work properly. 'occupation=01%02' works fine (change url directly in internet browser), but it throws an error when 'occupation=01%2C02'(,) or 'occupation=01&occupation=02'.
This error occurs when requesting to the server with multiple values from the checkbox.
What is the problem? Is it an encoding problem? If I'm wrong, where would I go wrong?
I used html5 client and receive 10 from the server and paging them
in java:
uri = new URIBuilder()
.setScheme("http")
.setHost("openapi.work.go.kr")
.setPath("/opi/opi/opia/wantedApi.do")
.setParameter("returnType", "xml")
.setParameter("startPage", requestVo.getStartPage())
.setParameter("callTp", "L")
.setParameter("region", "30200")
.setParameter("occupation", requestVo.getOccupation())
.setParameter("keyword", requestVo.getKeyword())
.setParameter("authKey", requestVo.getKey())
.build();
in jsp :checkbox id is occupation_chbox and I put the value in
<input type="hidden" name="startPage" value="1">
using js
function jobsubmit(){
var form = document.getElementById("requestForm")
var occ = checkOcc();
$("#occupation").val(occ);
console.log($("#occupation").val());
form.submit();
}
function checkOcc(){
var chk_arr = [];
$("input[id='occupation_chbox']:checked").each(function(){
var chkBox = $(this).val();
chk_arr.push(chkBox);
})
console.log(chk_arr);
var occ="";
for(i = 0; i<chk_arr.length; i++){
occ += (i < chk_arr.length - 1) ? chk_arr[i] + "," : chk_arr[i]
}
console.log(occ);
return occ;
}
I solved this problem by changing the delimiter from ',' to '|'.
occ += (i < chk_arr.length - 1) ? chk_arr[i] + "|" : chk_arr[i]