Java tutorial
//package com.java2s; import java.util.Map; import java.util.Map.Entry; import org.apache.http.client.methods.HttpUriRequest; public class Main { private static void setHeader(HttpUriRequest request, Map<String, String> headers) { if (headers == null || headers.size() == 0) { throw new NullPointerException("headers not be null"); } for (Entry<String, String> entry : headers.entrySet()) { request.addHeader(entry.getKey(), entry.getValue()); } } }