소스 검색

add HttpUtil.get that takes two sets of headers

tags/2.0.1
Jonathan Cobb 4 년 전
부모
커밋
1bdd2482ba
1개의 변경된 파일12개의 추가작업 그리고 5개의 파일을 삭제
  1. +12
    -5
      src/main/java/org/cobbzilla/util/http/HttpUtil.java

+ 12
- 5
src/main/java/org/cobbzilla/util/http/HttpUtil.java 파일 보기

@@ -69,16 +69,23 @@ public class HttpUtil {
public static InputStream get (String urlString) throws IOException { return get(urlString, null); }

public static InputStream get (String urlString, Map<String, String> headers) throws IOException {
return get(urlString, headers, null);
}

public static InputStream get (String urlString, Map<String, String> headers, Map<String, String> headers2) throws IOException {
final URL url = new URL(urlString);
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
if (headers != null) {
for (Map.Entry<String, String> h : headers.entrySet()) {
urlConnection.setRequestProperty(h.getKey(), h.getValue());
}
}
if (headers != null) addHeaders(urlConnection, headers);
if (headers2 != null) addHeaders(urlConnection, headers2);
return urlConnection.getInputStream();
}

public static void addHeaders(HttpURLConnection urlConnection, Map<String, String> headers) {
for (Map.Entry<String, String> h : headers.entrySet()) {
urlConnection.setRequestProperty(h.getKey(), h.getValue());
}
}

public static HttpResponseBean upload (String url,
File file,
Map<String, String> headers) throws IOException {


불러오는 중...
취소
저장