package com.naver.api.service;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.transaction.Transactional;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.IOException;
public class NaverParse {
protected String parse(String url){
String clientId = "client_id";
String clientSecret = "client_secret";
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet(url);
request.addHeader("X-Naver-Client-Id", clientId);
request.addHeader("X-Naver-Client-Secret", clientSecret);
HttpResponse response = client.execute(request);
xml = EntityUtils.toString(response.getEntity());
} catch (IOException e) {
protected static String xml2json(String xml){
int PRETTY_PRINT_INDENT_FACTOR = 4;
JSONObject xmlJSONObj = null;
xmlJSONObj = XML.toJSONObject(xml);
json = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
} catch (JSONException e) {
댓글