Package java.net

Examples of java.net.HttpURLConnection.connect()


        try {
          LogHelper.showInfo("urbanDictionaryPleaseWait", sender);
          HttpURLConnection url = (HttpURLConnection) new URL("http://urbanscraper.herokuapp.com/define/" + args[0] + ".json").openConnection();
          url.setConnectTimeout(10000);
          url.setReadTimeout(10000);
          url.connect();
          if(url.getErrorStream() == null) {
            def = convertStreamToString((InputStream)url.getContent());
          }
        } catch (Exception e) {
          LogHelper.showWarnings(sender, "urbanDictionaryError");
View Full Code Here


    public static HttpURLConnection doRequest(OAuthClientRequest req) throws IOException {
        URL url = new URL(req.getLocationUri());
        HttpURLConnection c = (HttpURLConnection)url.openConnection();
        c.setInstanceFollowRedirects(true);
        c.connect();
        c.getResponseCode();

        return c;
    }
View Full Code Here

  @Test
  public void testCallIndexPage() throws Exception {
    URL url = new URL(this.baseUrl);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestProperty("Authorization", "bearer 74eccf5f-0995-4e1c-b08c-d05dd5a0f89b");
    connection.connect();
    assertEquals(200, connection.getResponseCode());
    String output = IOUtils.toString(connection.getInputStream());
    assertTrue(output.contains("emma.blunt"));
  }
View Full Code Here

      url = new URL(urlStr);
      HttpURLConnection httpsURLConnection = (HttpURLConnection) url.openConnection();

      httpsURLConnection.setRequestMethod("GET");
      httpsURLConnection.setConnectTimeout(5 * 1000);
      httpsURLConnection.connect();
      if (httpsURLConnection.getResponseCode() == 200) {
        // 通过输入流获取网络图片
        InputStream inputStream = httpsURLConnection.getInputStream();
        String data = readHtml(inputStream, "UTF-8");
        inputStream.close();
View Full Code Here

      url = new URL(urlStr);
      HttpURLConnection httpsURLConnection = (HttpURLConnection) url.openConnection();

      httpsURLConnection.setRequestMethod("GET");
      httpsURLConnection.setConnectTimeout(5 * 1000);
      httpsURLConnection.connect();
      if (httpsURLConnection.getResponseCode() == 200) {
        // 通过输入流获取网络图片
        InputStream inputStream = httpsURLConnection.getInputStream();
        String data = readHtml(inputStream, "GBK");
        inputStream.close();
View Full Code Here

      HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
      httpConn.setRequestMethod("GET");
      httpConn.setConnectTimeout(15000);
      httpConn.setReadTimeout(20000);
      httpConn.connect();
      if (httpConn.getResponseCode() == 200) {
        String sessionId = "";
        String cookieVal = null;
        String key = null;
        for (int i = 1; (key = httpConn.getHeaderFieldKey(i)) != null; i++) {
View Full Code Here

                BufferedOutputStream output = new BufferedOutputStream(connection.getOutputStream());
                output.write(payload.getBytes());
                output.close();
            }

            connection.connect();
            InputStream responseBodyStream = connection.getInputStream();
            StringBuffer responseBody = new StringBuffer();
            while ((read = responseBodyStream.read(buffer)) != -1) {
                responseBody.append(new String(buffer, 0, read));
            }
View Full Code Here

         
          if (post) {
            c.setDoInput(true);
            c.setDoOutput(true);
            c.setUseCaches(false);
            c.connect();
            int postlen = Integer.parseInt(headers.get("content-length"));
            byte[] postdata = new byte[postlen];
            fromClient.read(postdata);
           
            DataOutputStream os = new DataOutputStream(c.getOutputStream());
View Full Code Here

                    try {
                        conn = (HttpURLConnection) moduleUrl.openConnection();
                        conn.setUseCaches(false);
                        conn.setRequestMethod("GET"); //$NON-NLS-1$
                        conn.setReadTimeout(5000);
                        conn.connect();
                        code = conn.getResponseCode();
                        if (code != HttpURLConnection.HTTP_NOT_FOUND) {
                            return true;
                        }
                    } catch (Throwable e) {
View Full Code Here

    private HttpURLConnection openConnection(URL url) throws IOException
    {
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty(HDR_X_FORWARDED_PROTO, HTTPS);
        conn.setRequestProperty(HDR_X_FORWARDED_SSL, "on");
        conn.connect();
        return conn;
    }

    private URL createURL(String path) throws MalformedURLException
    {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.