Examples of WWWConnection


Examples of com.draagon.wii.util.WWWConnection

      // Open the URL connection
      URL url = new URL( base );
      // URLConnection conn = url.openConnection();
      // System.out.println( "--- create connection: " + url );
      WWWConnection conn = new WWWConnection( url );
      // System.out.println( "--- open connection" );

      conn.open();

      // conn.setDoInput( true );

      // System.out.println( "--- START input parameters" );
      for( NameValuePair pair : headers )
      {
        if ( log.isDebugEnabled() )
          log.debug( "(doRequest) Request header: [" + pair.getName() + "][" + pair.getValue() + "]" );

        conn.setRequestProperty( pair.getName(), pair.getValue() );
      }

      int i = base.indexOf( '/' );
      if ( i > 0 )
      {
        while( base.charAt( i ) == '/' ) i++;

        String tmp = base.substring( i );

        int j = tmp.indexOf( '/' );
        if ( j > 0 ) tmp = tmp.substring( 0, j );

        //ystem.out.println( "HOST: " + tmp );
        conn.setRequestProperty( "host", tmp );
      }

      // System.out.println( "--- END input parameters" );

      // conn.setUseCaches( false );

      // If a POST was called the send that data to the server
      if ( isPost )
      {
          int rc = 0;

          // conn.setDoOutput( true);

          // System.out.println( "--- get input stream" );
          InputStream in = mRequest.getInputStream();
          // System.out.println( "--- get output stream" );
          OutputStream os = conn.getOutputStream();

          // System.out.println( "--- read data" );
          while( ( rc = in.read( buf, 0, 1024 )) >= 0 )
          {
            // System.out.println( "--- write data" );
            os.write( buf, 0, rc );
          }

          // os.close();
      }

      // Return any HTTP Response Headers, including Cookies
      // System.out.println( "--- get input stream" );
      is = conn.getInputStream();
      // System.out.println( "--- get content type" );
      mContentType = conn.getContentType();
      mStatusCode = conn.getStatusCode();

      //while( (head = conn.getHeaderField( i )) != null )
      // System.out.println( "--- Process headers" );
      for ( NameValuePair pair : conn.getHeaders() )
      {
          String name = pair.getName();
          String value = pair.getValue();

          if ( log.isDebugEnabled() )
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.