Package java.net

Examples of java.net.HttpURLConnection


   * @throws JDOMException
   */
  public void load(User user) throws IOException, JDOMException
  {
        URL url = new URL(FetionConfig.getString("server.nav-system-uri"));
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.addRequestProperty("User-Agent", "IIC2.0/PC "+FetionClient.PROTOCOL_VERSION);
       
        String accountType = null;
        if(user.getMobile()>0){
          accountType = "mobile-no=\""+user.getMobile()+"\"";
        }else if(user.getFetionId()>0){
          accountType = "sid=\""+user.getFetionId()+"\"";
        }else if(user.getEmail()!=null){
          accountType = "email=\""+user.getEmail()+"\"";
        }else{
          throw new IllegalStateException("Invalid CMCC mobile number, FetionId or Registered Email.");
        }
       
        String content = "<config><user "+accountType+" /><client type=\"PC\" version=\""+FetionClient.PROTOCOL_VERSION+"\" platform=\"W5.1\" /><servers version=\"0\" /><service-no version=\"0\" /><parameters version=\"0\" /><hints version=\"0\" /><http-applications version=\"0\" /><client-config version=\"0\" /><services version=\"0\" /></config>";
        OutputStream out = conn.getOutputStream();
        out.write(content.getBytes());
        out.flush();
       
        SAXBuilder builder = new SAXBuilder();
        this.document = builder.build(conn.getInputStream());
        this.isLoaded = true;
  }
View Full Code Here


  {
      String picurl = setting.getNodeText("/config/servers/get-pic-code");
      if(picurl==null) picurl = FetionConfig.getString("server.verify-pic-uri");
      picurl +="?algorithm="+alg;
          URL url = new URL(picurl);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.addRequestProperty("User-Agent", "IIC2.0/PC "+FetionClient.PROTOCOL_VERSION);    //必须要加这个,否则失败  很奇怪
          if(conn.getResponseCode()==HttpURLConnection.HTTP_OK) {
            Element e = XMLHelper.build(conn.getInputStream());
        Element pic = XMLHelper.find(e, "/results/pic-certificate");
        String pid = pic.getAttributeValue("id");
        String code = pic.getAttributeValue("pic");
        byte[] base64Data = code.getBytes();
        byte[] bytes = Base64.decodeBase64(base64Data);
            return new VerifyImage(pid, bytes, alg, type);
          }else {
            throw new IOException("Http response is not OK. code="+conn.getResponseCode());
          }
  }
View Full Code Here

   * @param responseCode
   * @return
   */
  public boolean status(int responseCode) {
    if (urlConnection instanceof HttpURLConnection) {
      HttpURLConnection http = (HttpURLConnection) urlConnection;
      try {
        return http.getResponseCode() == responseCode;
      } catch (IOException e) {
        e.printStackTrace();
        return false;
      }
    } else
View Full Code Here

      try {
        conn = urlToRetrieve.openConnection();

        if (conn instanceof HttpURLConnection) {

          HttpURLConnection httpConn = (HttpURLConnection) conn;

          httpConn.setInstanceFollowRedirects(true); // not needed, default ?

          //   Hack for User-Agent : problem for
          // http://www.diveintomark.org/xml/rss.xml
          HttpHeaderUtils.setUserAgent(httpConn, "Informa Java API");
View Full Code Here

      try {
        conn = aURL.openConnection();

        if (conn instanceof HttpURLConnection) {

          HttpURLConnection httpConn = (HttpURLConnection) conn;

          httpConn.setInstanceFollowRedirects(true);
          //   Hack for User-Agent : problem for
          // http://www.diveintomark.org/xml/rss.xml
          HttpHeaderUtils.setUserAgent(httpConn, "Informa Java API");
          HttpHeaderUtils.setETagValue(httpConn, this.httpHeaders.getETag());
          HttpHeaderUtils.setIfModifiedSince(httpConn, this.httpHeaders
              .getIfModifiedSince());
          httpConn.connect();
          if (httpConn.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {

            logger.info("cond. GET for feed at url " + feedUrl + ": no change");
            this.feed.setLastUpdated(new Date());
            // TODO : add a property in FeedIF interface for lastGet ?
            this.lastUpdate = System.currentTimeMillis();
View Full Code Here

  public static String readString(String url, int timeout) {
    Reader reader = null;
    try {
      URLConnection uc = new URL(url).openConnection();
      if (uc instanceof HttpURLConnection) {
        HttpURLConnection httpConnection = (HttpURLConnection) uc;
        httpConnection.setConnectTimeout(timeout * 1000);
        httpConnection.setReadTimeout(timeout * 1000);
      }
      Matcher matcher = Pattern.compile("://(\\w+:\\w+)@").matcher(url);
      if (matcher.find()) {
        String auth = matcher.group(1);
        String encoding = Base64.encodeBytes(auth.getBytes());
View Full Code Here

   */
  public static boolean isConnectable(String url, int timeout) {
    try {
      URLConnection connection = new URL(url).openConnection();
      if (connection instanceof HttpURLConnection) {
        HttpURLConnection httpConnection = (HttpURLConnection) connection;
        httpConnection.setConnectTimeout(timeout * 1000);
        httpConnection.setReadTimeout(timeout * 1000);
        httpConnection.connect();
        int response = httpConnection.getResponseCode();
        httpConnection.disconnect();
        return response == HttpURLConnection.HTTP_OK;
      }
    } catch (Exception e) {
      return false;
    }
View Full Code Here

   */
  public static int getStatus(String url, int timeout) {
    try {
      URLConnection connection = new URL(url).openConnection();
      if (connection instanceof HttpURLConnection) {
        HttpURLConnection httpConnection = (HttpURLConnection) connection;
        httpConnection.setConnectTimeout(timeout * 1000);
        httpConnection.setReadTimeout(timeout * 1000);
        httpConnection.connect();
        int response = httpConnection.getResponseCode();
        httpConnection.disconnect();
        return response;
      }
    } catch (IOException e) {
      // pass
    }
View Full Code Here

          citeseerURLString.append(OAI_URL);
          citeseerURLString.append(OAI_ACTION);
          citeseerURLString.append("&" + OAI_METADATAPREFIX);
                    citeseerURLString.append("&" + "identifier=").append(key);
          URL citeseerUrl = new URL( citeseerURLString.toString());
          HttpURLConnection citeseerConnection = (HttpURLConnection)citeseerUrl.openConnection();       
          saxParser.parse(citeseerConnection.getInputStream(), new CiteSeerUndoHandler(dummyNamedCompound, newEntry, panel, dummyBoolean));
          database.insertEntry(newEntry);
          citationCounter++;
          UpdateProgressBarTwoValue updateValue = new UpdateProgressBarTwoValue(citationCounter);
          SwingUtilities.invokeLater(updateValue);
          }
View Full Code Here

                      citeseerURLString.append(OAI_URL);
                      citeseerURLString.append(OAI_ACTION);
                      citeseerURLString.append("&" + OAI_METADATAPREFIX);
                        citeseerURLString.append("&" + "identifier=").append(identifier);
                      URL citeseerUrl = new URL( citeseerURLString.toString());
                      HttpURLConnection citeseerConnection = (HttpURLConnection)citeseerUrl.openConnection();       
                      saxParser.parse(citeseerConnection.getInputStream(), new CiteSeerCitationHandler(citationHashTable));
                    } else {
                      int row = panel.mainTable.findEntry(currentEntry);
                      rejectedEntries.put(new Integer(row+1),currentEntry);                    
                    }
    } catch (SAXException e) {
View Full Code Here

TOP

Related Classes of java.net.HttpURLConnection

Copyright © 2018 www.massapicom. 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.