Examples of HttpURLConnection


Examples of java.net.HttpURLConnection

      try {
        URL url = new URL(serverURL);

        System.out.println("connecting to the server...");
        HttpURLConnection con = (HttpURLConnection)url.openConnection();
        con.setDoOutput(true);
        con.setRequestMethod("POST");

        if (keyString != null) {
          String form = HttpClientUtil.encodeParameter(SesameServer.SHUTDOWN_KEY_PARAM, keyString);
          OutputStream out = con.getOutputStream();
          out.write(form.getBytes("ISO-8859-1"));
        }

        if (HttpClientUtil.is2xx(con.getResponseCode())) {
          System.out.println("shutdown command sent successfully");
        }
        else {
          System.out.println("Shutdown request failed: " + con.getResponseMessage());
          System.exit(3);
        }
      }
      catch (MalformedURLException e) {
        System.err.println("Malformed URL: " + serverURL);
View Full Code Here

Examples of java.net.HttpURLConnection

      sParams += aParams[p].getName()+"="+URLEncoder.encode(aParams[p].getValue(), "UTF-8");
      if (p<aParams.length-1) sParams += "&";
    } // next
  } // fi

    HttpURLConnection oCon = (HttpURLConnection) oUrl.openConnection();
   
    oCon.setUseCaches(false);
    oCon.setFollowRedirects(false);
    oCon.setInstanceFollowRedirects(false);
    oCon.setDoInput (true);

    oCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  oCon.setRequestProperty("Content-Length", String.valueOf(sParams.getBytes().length));
  oCon.setFixedLengthStreamingMode(sParams.getBytes().length);
    oCon.setDoOutput(true);
  oCon.setRequestMethod("POST");
  OutputStreamWriter oWrt = new OutputStreamWriter(oCon.getOutputStream());
    oWrt.write(sParams);
    oWrt.flush();
    oWrt.close();

  int responseCode = oCon.getResponseCode();

  if (responseCode == HttpURLConnection.HTTP_MOVED_PERM ||
    responseCode == HttpURLConnection.HTTP_MOVED_TEMP) {

      HttpRequest oMoved = new HttpRequest(oCon.getHeaderField("Location"), oUrl, "POST", aParams);   
    oRetVal = oMoved.post();
    sUrl = oMoved.url();
  } else if (responseCode == HttpURLConnection.HTTP_OK ||
      responseCode == HttpURLConnection.HTTP_ACCEPTED) {
    InputStream oStm = oCon.getInputStream();
    String sEnc = oCon.getContentEncoding();
    if (sEnc==null) {
      ByteArrayOutputStream oBya = new ByteArrayOutputStream();
      new StreamPipe().between(oStm, oBya);
      oRetVal = oBya.toByteArray();
    } else {
      int c;
      StringBuffer oDoc = new StringBuffer();
      Reader oRdr = new InputStreamReader(oStm, sEnc);
      while ((c=oRdr.read())!=-1) {
        oDoc.append((char) c);
      } // wend
      oRdr.close();
      oRetVal = oDoc.toString();
    }
    oStm.close();
  } else {
    throw new IOException(String.valueOf(responseCode));
  }
  oCon.disconnect();
  return oRetVal;
  } // post
View Full Code Here

Examples of sun.net.www.protocol.http.HttpURLConnection

                p = new Proxy(Proxy.Type.HTTP, saddr);
            }
        }
        if (p != null) {
            return new HttpURLConnection(u, p);
        }

        return new GopherURLConnection(u);
    }
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.