List of usage examples for java.net HttpURLConnection setRequestProperty
public void setRequestProperty(String key, String value)
From source file:me.sonarbeserk.lockup.utils.UUIDFetcher.java
private static HttpURLConnection createConnection(int page) throws Exception { URL url = new URL(PROFILE_URL + page); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setUseCaches(false);//from ww w . j a v a 2 s .c o m connection.setDoInput(true); connection.setDoOutput(true); return connection; }
From source file:com.publicuhc.pluginframework.util.UUIDFetcher.java
protected static HttpURLConnection getConnection() throws IOException { URL url = new URL(PROFILE_URL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setUseCaches(false);//from ww w . j a v a 2s.co m connection.setDoInput(true); connection.setDoOutput(true); return connection; }
From source file:com.dianping.phoenix.dev.core.tools.generator.stable.GitRepositoryListGenerator.java
private static int curl_code(String url) throws Exception { URL reqUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) reqUrl.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(3000);// w ww. j a va2 s . c o m conn.setRequestProperty("Cookie", "uid=code51c3bceea328e0.87696853; remember_user_token=BAhbB1sGaXFJIiIkMmEkMTAkQUR2YXNENGNqT2NSaDBvVWRSS2guTwY6BkVU--bd148a50388e51e524e89809afd6d98e69793711; request_method=GET; _gitlab_session=BAh7CEkiD3Nlc3Npb25faWQGOgZFRkkiJTMzY2U3YzM3YjlhZWQ1ODcwNDljNDA0MjFkOTdjZjA4BjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMTNqS1V3V2paUCtCWU0rbVZtTUVraFBpTDR3MGFpZ2FtaExXeWphYjJRSVE9BjsARkkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsHWwZpcUkiIiQyYSQxMCRBRHZhc0Q0Y2pPY1JoMG9VZFJLaC5PBjsAVA%3D%3D--af5d6859bcba9e86e72ca6c3b2430400db75dcad"); return conn.getResponseCode(); }
From source file:Main.java
public static int sendMessage(String auth_token, String registrationId, String message) throws IOException { StringBuilder postDataBuilder = new StringBuilder(); postDataBuilder.append(PARAM_REGISTRATION_ID).append("=").append(registrationId); postDataBuilder.append("&").append(PARAM_COLLAPSE_KEY).append("=").append("0"); postDataBuilder.append("&").append("data.payload").append("=") .append(URLEncoder.encode("Lars war hier", UTF8)); byte[] postData = postDataBuilder.toString().getBytes(UTF8); // Hit the dm URL. URL url = new URL("https://android.clients.google.com/c2dm/send"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true);/*www . ja va 2s . c o m*/ conn.setUseCaches(false); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); conn.setRequestProperty("Content-Length", Integer.toString(postData.length)); conn.setRequestProperty("Authorization", "GoogleLogin auth=" + auth_token); OutputStream out = conn.getOutputStream(); out.write(postData); out.close(); int responseCode = conn.getResponseCode(); return responseCode; }
From source file:com.memetix.gun4j.GunshortenAPI.java
protected static JSONObject post(final String serviceUrl, final String paramsString) throws Exception { final URL url = new URL(serviceUrl); final HttpURLConnection uc = (HttpURLConnection) url.openConnection(); if (referrer != null) uc.setRequestProperty("referer", referrer); uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=" + ENCODING); uc.setRequestProperty("Accept-Charset", ENCODING); uc.setRequestMethod("POST"); uc.setDoOutput(true);/*from ww w.jav a2 s. co m*/ final PrintWriter pw = new PrintWriter(uc.getOutputStream()); pw.write(paramsString); pw.close(); uc.getOutputStream().close(); try { final int responseCode = uc.getResponseCode(); final String result = inputStreamToString(uc.getInputStream()); if (responseCode != 200) { throw new Exception("Error from Gunshorten API: " + result); } return parseJSON(result); } finally { uc.getInputStream().close(); if (uc.getErrorStream() != null) { uc.getErrorStream().close(); } } }
From source file:com.facebook.fresco.sample.urlsfetcher.ImageUrlsFetcher.java
@Nullable private static String downloadContentAsString(String urlString) throws IOException { InputStream is = null;/*from ww w .j av a2 s . c o m*/ try { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", IMGUR_CLIENT_ID); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */); conn.setRequestMethod("GET"); conn.setDoInput(true); // Starts the query conn.connect(); int response = conn.getResponseCode(); if (response != HttpStatus.SC_OK) { FLog.e(TAG, "Album request returned %s", response); return null; } is = conn.getInputStream(); return readAsString(is); } finally { if (is != null) { is.close(); } } }
From source file:com.adguard.compiler.UrlUtils.java
public static String downloadString(URL url, String encoding, String userAgent) throws IOException { HttpURLConnection connection = null; InputStream inputStream = null; try {//from w w w .j av a 2s . c om connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent", userAgent); connection.connect(); inputStream = connection.getInputStream(); return IOUtils.toString(inputStream, encoding); } finally { IOUtils.closeQuietly(inputStream); if (connection != null) { connection.disconnect(); } } }
From source file:FainClasses.HttpBasicAuth.java
public static void auth() { String sHTML = "Can not load page"; URL url;//from www.j a v a2 s . c o m InputStream is; BufferedReader buff = null; try { url = new URL("http://vrgaz.ru/lk/index.php?page=ls&lss=1600013620"); url.getAuthority(); String encoding = Base64.encodeBase64String("md_dimka@mail.ru:ufpyflt;ls".getBytes()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setRequestProperty("Cookie", "PHPSESSID=343266771f5de3a489ba82fe79809854"); // connection. //connection.setRequestProperty("Authorization", "Basic " + encoding); /*connection.setRequestProperty("avl","md_dimka@mail.ru"); connection.setRequestProperty("avp","ufpyflt;ls"); */ //connection.setRequestProperty("page", "ls"); //connection.setRequestProperty("lss", "1600013620"); //URL url = new URL("http://vrgaz.ru/lk/"); // url = new URL(sUrl); //is = url.openStream(); is = connection.getInputStream(); buff = new BufferedReader(new InputStreamReader(is, "windows-1251")); StringBuilder page = new StringBuilder(); String tmp; while ((tmp = buff.readLine()) != null) { page.append(tmp).append("\n"); } sHTML = page.toString(); System.out.println(sHTML); // InputStream content = (InputStream) connection.getInputStream(); // BufferedReader in // = new BufferedReader(new InputStreamReader(content)); // String line; // while ((line = in.readLine()) != null) { // System.out.println(line); // } } catch (Exception e) { e.printStackTrace(); } }
From source file:Yak_Hax.Yak_Hax_Mimerme.PostRequest.java
public static String PostBodyRequest(String URL, String JSONRaw, String UserAgent) throws IOException { String type = "application/json"; URL u = new URL(URL); HttpURLConnection conn = (HttpURLConnection) u.openConnection(); conn.setDoOutput(true);/*from w ww . j av a 2 s . c o m*/ conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", type); conn.setRequestProperty("User-Agent", UserAgent); OutputStream os = conn.getOutputStream(); os.write(JSONRaw.getBytes()); os.flush(); os.close(); String response = null; DataInputStream input = new DataInputStream(conn.getInputStream()); while (null != ((response = input.readLine()))) { input.close(); return response; } return null; }
From source file:com.choices.imagecompare.urlsfetcher.ImageUrlsFetcher.java
@Nullable private static String downloadContentAsString(String urlString) throws IOException { InputStream is = null;/*ww w .ja v a2 s .c om*/ try { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", IMGUR_CLIENT_ID); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */); conn.setRequestMethod("GET"); conn.setDoInput(true); // Starts the query conn.connect(); int response = conn.getResponseCode(); if (response != SC_OK) { FLog.e(TAG, "Album request returned %s", response); return null; } is = conn.getInputStream(); return readAsString(is); } finally { if (is != null) { is.close(); } } }