보난자 API에 간단한 GET 요청을 보내려고합니다.자바를 사용하여 보난자 API GET 요청 보내기
그들은 PHP 예제를 제공하지만 JAVA에서 작동하도록 만들 수 없습니다.
이
은 보난자 에서 PHP 예 http://api.bonanza.com/docs/examples/php#get_booth$dev_name = "xxx";
$api_url = "http://api.bonanza.com/api_requests/standard_request";
$headers = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$args = array("userId" => "rooms_delivered");
$post_fields = "getBoothRequest=" . json_encode($args, JSON_HEX_AMP);
echo "Request: $post_fields \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$headers, CURLOPT_POSTFIELDS=>$post_fields,
CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1); # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
echo curl_error($connection) . "\n";
exit(2);
}
curl_close($connection);
$response = json_decode($json_response,true);
echo "Response: \n";
print_r($response);
는 코드 페이지 나는 "stavgallery"을 얻을 필요가 http://api.bonanza.com/docs/reference/get_booth
부스
입니다 이것은 내가 무엇이다. 아베가 지금까지 (Eclipse IDE를 사용하여) :
String devId = "HIDDEN";
JSONArray stArray = new JSONArray();
JSONObject jsonObj = new JSONObject("{'userId':'stavgallery'}");
stArray.put(jsonObj);
JSONObject jsonObjFull = new JSONObject("{'getBoothRequest':"+stArray+"}");
System.out.println(jsonObjFull.toString());
int inputLine;
URL url = new URL("http://api.bonanza.com/api_requests/standard_request");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("X-BONANZLE-API-DEV-NAME", devId);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(jsonObjFull.toString());
writer.flush();
writer.close();
inputLine = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
JSONObject sampleReturn = new JSONObject(in.readLine());
System.out.println(sampleReturn);
점점 오류
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://api.bonanza.com/api_requests/standard_request
더 많은 정보가 필요한 경우
업데이트? 오라클에 돈을 걸 겠어. – rightfold
hehe 감사 수정을 위해 – zvikachu