Google의 URL Shortener API를 사용하려고합니다.Apache HttpClient 프로세스 HttpResponse
처럼 얻을 응답이 보일 것입니다 : 내가 JSON 내가 'ID'필드를 액세스하고 단축 URL을 얻을 수 있도록 반환 처리 할 수 있도록하려면
200
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-encoding: gzip
content-length: 106
content-type: application/json; charset=UTF-8
date: Thu, 07 Dec 2017 23:39:07 GMT
etag: "qQqhpr1RL6vGc3-0yacNoUjh_Uc/W5VD-15ZqaQDW9L-OELlMzo1ih4"
expires: Mon, 01 Jan 1990 00:00:00 GMT
pragma: no-cache
server: GSE
vary: Origin, X-Origin
{
"kind": "urlshortener#url",
"id": "[SHORTENED URL HERE]",
"longUrl": "http://www.facebook.com/"
}
.
그러나 나는이 같은 외모를 얻고 있다는 응답 : 누군가가 내가 얻을 수 있도록 'ID'JSON 필드에 접근하는 방법을 파악하는 데 도움 수 있다면Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Date: Fri, 08 Dec 2017 10:10:37 GMT
ETag: "qQqhpr1RL6vGc3-0yacNoUjh_Uc/W5VD-15ZqaQDW9L-OELlMzo1ih4"
Vary: Origin
Vary: X-Origin
Content-Type: application/json; charset=UTF-8
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
Transfer-Encoding: chunked
내가 그것을 감사하겠습니다 단축 URL
는이에 대한 나의 코드는 다음과 같습니다
HttpPost httppost = new HttpPost("https://www.googleapis.com/urlshortener/v1/url?key=[MY_API_KEY]);
String jsondata = "{\"longUrl\": \"http://www.facebook.com/\"}";
StringEntity jsonparam = new StringEntity(jsondata);
jsonparam.setContentType("application/json;charset=utf-8");
jsonparam.setChunked(false);
httppost.addHeader("content-type", "application/json;charset=UTF-8");
httppost.setEntity(jsonparam);
HttpClient httpclient = HttpClientBuilder.create().build();
HttpResponse httpresponse = httpclient.execute(httppost);
Header[] headers = httpresponse.getAllHeaders();
for (Header header : headers) {
System.out.println(header);
}
헤더를 인쇄 중이면 본문을 인쇄해야합니다. – tkausl
어떻게해야합니까? 본문을 가져 오려고 할 때'org.apache.http.client.entity.DecompressingEntity @ 11e21d0e'를 반환합니다. –