PHP Example
<?php
// 사람인 채용공고 API 샘플
$params = [
'access-key' => '발급 받은 키',
'keyword' => '',
];
$url = "https://oapi.saramin.co.kr/job-search";
$url = $url . '?' . http_build_query($params, '', '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept' => 'application/json', 'Content-Type' => 'application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if($status_code == 200) {
$data = json_decode($response, TRUE);
var_dump($data);
} else {
echo "Error 내용:".$response;
}
?>
JAVA Example
package kr.co.saramin.oapi;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
/**
* 사람인 채용공고 API 샘플
*/
public class Sample {
public static void main(String[] args) {
String accessKey = "accessKey"; // 발급받은 accessKey";
try {
String text = URLEncoder.encode("", "UTF-8");
String apiURL = "https://oapi.saramin.co.kr/job-search?access-key="+accessKey+"&keyword="+ text;
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Accept", "application/json");
int responseCode = con.getResponseCode();
BufferedReader br;
if(responseCode==200) { // 정상 호출
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else { // 에러 발생
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
System.out.println(response.toString());
} catch (Exception e) {
System.out.println(e);
}
}
}