package com.smtscript.lib; import java.net.HttpURLConnection; import java.util.List; import java.util.Map.Entry; import org.mozilla.javascript.NativeObject; import com.smtscript.lib.http.JSHttpClient; import com.smtscript.utils.HttpClient; import com.smtscript.utils.JSCommentDoc; import com.smtscript.utils.SMTStatic; public class JSStaticHttp extends JSStaticAbstract { public JSHttpClient create() { return new JSHttpClient(this); } @JSComment( JSCommentDoc.HTTP_QUERY_URL ) public String queryHttpString(Object url) throws Exception { return create().queryHttpString(url); } @JSComment( JSCommentDoc.HTTP_QUERY_URL ) public void queryHttpFile(Object url, String fileName) throws Exception { create().queryHttpFile(url, fileName); } public String encodeURIComponent(String s) throws Exception { return HttpClient.encodeURIComponent(s, "UTF-8"); } public String encodeURIComponent(String s, String encode) throws Exception { return HttpClient.encodeURIComponent(s, encode); } public int getConnRespCode(Object conn) throws Exception { return ((HttpURLConnection)conn).getResponseCode(); } public NativeObject getConnRespHeaders(Object conn) { NativeObject ret = new NativeObject(); for(Entry> entry : ((HttpURLConnection)conn).getHeaderFields().entrySet()) { String key = entry.getKey(); if(SMTStatic.isNullOrEmpty(key)) key = ""; SMTStatic.putJSNotNullValue(ret, key.toLowerCase(), entry.getValue().get(0)); } return ret; } }