C# Zip

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aung

    #1

    C# Zip

    Has anybody develop RFC1950 and RFC1951 compliant Zip utility?

    Any pointer will be appreciated.



  • Pieter Philippaerts

    #2
    Re: C# Zip

    "Aung" <aung@aungkyawm oe_NOSPAM_.net> wrote in message
    news:ej7TvB1aDH A.736@TK2MSFTNG P09.phx.gbl...[color=blue]
    > Has anybody develop RFC1950 and RFC1951 compliant Zip utility?
    > Any pointer will be appreciated.[/color]

    ICSharpCode has 22 repositories available. Follow their code on GitHub.


    Regards,
    Pieter Philippaerts
    Managed SSL/TLS: http://www.mentalis.org/go.php?sl


    Comment

    • AlexL [Xceed]

      #3
      Re: C# Zip

      If you're looking for a full-featured one, please check out Xceed Zip
      for .NET:



      Alex

      On Mon, 25 Aug 2003 04:32:40 +0700, "Aung"
      <aung@aungkyawm oe_NOSPAM_.net> wrote:
      [color=blue]
      >Has anybody develop RFC1950 and RFC1951 compliant Zip utility?
      >
      >Any pointer will be appreciated.
      >
      >[/color]

      --
      Alex Leblanc
      Xceed Software Inc.


      Check out our advanced .NET grid and SmartUI controls

      Email: xLeblancA@xceed soft.com (remove the first 'x')

      Comment

      • Joe

        #4
        Re: C# Zip

        "Bruno Jouhier [MVP]" <bjouhier@clu b-internet.fr> wrote in message
        news:ef33jYAbDH A.424@TK2MSFTNG P10.phx.gbl...[color=blue]
        > You can get one from J#:
        >
        > You just need to add a reference to vjslib.dll to your C# project.
        > The ZIP API is in the java.util.zip namespace.
        > Unfortunately, this API is based on Java streams (java.io stuff) rather[/color]
        than[color=blue]
        > .NET streams (System.IO stuff), so you'll have to deal with some Java
        > idiosyncrasies.
        >
        > Bruno.
        >
        >
        > "Aung" <aung@aungkyawm oe_NOSPAM_.net> a écrit dans le message de
        > news:ej7TvB1aDH A.736@TK2MSFTNG P09.phx.gbl...[color=green]
        > > Has anybody develop RFC1950 and RFC1951 compliant Zip utility?[/color][/color]

        Here's an MSDN article that explains how to do what Bruno was suggesting:

        http://msdn.microsoft.com/msdnmag/is...n/default.aspx

        Joe
        --
        Learn C# with step-by-step tutorials and practical examples. Start your first program, explore lists and parsing, and understand how .NET runs your code.



        Comment

        • Odi [Xceed]

          #5
          Re: C# Zip

          Hi,

          We're not selling vaporware, Pete. The features are already
          implemented, tested, and ready to use today.

          Its easy to say something is expensive until you realize how much time
          you spend trying to DIY. Xceed caters to developers that want
          reliable, tested code that is well documented... so they can save
          their time. After all, time is money. That's what the value of the
          product is.

          With Xceed Zip for .NET, you'll get complete documentation, lots of
          samples, free tech support (try calling up the makers of the alternate
          solution you talk of and see if they'll stop what they are doing to
          help you until your problem is fixed), a web site with a knowledge
          base, online forums dedicated to the product, new versions and updates
          on a regular basis, and of couse, dozens upon dozens of features that
          only we do and nobody else does... not to mention the fact that these
          days we include all our other non-visual components and libraries in
          the price of the component as well...

          That's why we are developing an FTP library for .NET (plenty of free
          solutions for that... How many actually work well and are full
          featured?) and also why we made a Grid for .NET (why not just use the
          included datagrid with Visual Studio .NET?!)

          Take care,
          Odi

          On Wed, 27 Aug 2003 00:14:08 +0100, "Pete" <pvidler@gawab. com> wrote:
          [color=blue]
          >Hi,
          >
          >AlexL [Xceed] wrote:[color=green]
          >> If you're looking for a full-featured one, please check out Xceed Zip
          >> for .NET:
          >>
          >> http://www.xceedsoft.com/products/zipnet[/color]
          >
          >That's pretty damn expensive for a component that only does zip based
          >compression. The sharpziplib link posted before does other formats too and
          >is open source (extra features probably wouldn't be that difficult to
          >add/request -- someone on the team might even add them for you for less than
          >that xceed thing costs).
          >
          >Pete
          >[/color]

          --
          Alex Leblanc
          Xceed Software Inc.


          Check out our advanced .NET grid and SmartUI controls

          Email: xLeblancA@xceed soft.com (remove the first 'x')

          Comment

          • Joe

            #6
            Re: C# Zip

            Whoa, Odi, be careful man! I think Microsoft owns the copyright on the
            entire email you just wrote.

            -- Joe


            "Odi [Xceed]" <KosmatosO@xcee dsoft.com> wrote in message
            news:r54qkv8pq8 0sg2l3n1v0lcjd0 6p6eer6ft@4ax.c om...[color=blue]
            > Hi,
            >
            > We're not selling vaporware, Pete. The features are already
            > implemented, tested, and ready to use today.
            >
            > Its easy to say something is expensive until you realize how much time
            > you spend trying to DIY. Xceed caters to developers that want
            > reliable, tested code that is well documented... so they can save
            > their time. After all, time is money. That's what the value of the
            > product is.
            >
            > With Xceed Zip for .NET, you'll get complete documentation, lots of
            > samples, free tech support (try calling up the makers of the alternate
            > solution you talk of and see if they'll stop what they are doing to
            > help you until your problem is fixed), a web site with a knowledge
            > base, online forums dedicated to the product, new versions and updates
            > on a regular basis, and of couse, dozens upon dozens of features that
            > only we do and nobody else does... not to mention the fact that these
            > days we include all our other non-visual components and libraries in
            > the price of the component as well...
            >
            > That's why we are developing an FTP library for .NET (plenty of free
            > solutions for that... How many actually work well and are full
            > featured?) and also why we made a Grid for .NET (why not just use the
            > included datagrid with Visual Studio .NET?!)
            >
            > Take care,
            > Odi[/color]


            Comment

            • Aung

              #7
              HTTPS with WebResponse class

              Hello,

              I am having a problem with WebRequest class. I used the following code to
              post some data to a page and retrive back the response. It works fine with
              http:// connection. When i use that with https:// connection, it thrown an
              exception "The underlying connection was closed: Could not establish trust
              relationship with remote server.". I am using self sign certificate on the
              web server and the root and CA certificates are installed on the client
              machine using the following code.

              your suggestions will be great appreciated.

              Aung

              public string postForm(string url, string postData)

              {

              string retStr="", tempStr;

              HttpWebResponse result = null;

              try

              {

              HttpWebRequest req = (HttpWebRequest ) WebRequest.Crea te(url);

              req.Method = "POST";

              req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR
              1.0.3705)";

              req.ContentType = "applicatio n/x-www-form-urlencoded";

              StringBuilder UrlEncoded = new StringBuilder() ;

              Char[] reserved = {'?', '=', '&'};

              byte[] SomeBytes = null;

              if (postData != null)

              {

              int i=0, j;

              while(i<postDat a.Length)

              {

              j=postData.Inde xOfAny(reserved , i);

              if (j==-1)

              {

              UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i ,
              postData.Length-i)));

              break;

              }

              UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i , j-i)));

              UrlEncoded.Appe nd(postData.Sub string(j,1));

              i = j+1;

              }

              SomeBytes = Encoding.UTF8.G etBytes(UrlEnco ded.ToString()) ;

              req.ContentLeng th = SomeBytes.Lengt h;

              Stream newStream = req.GetRequestS tream();

              newStream.Write (SomeBytes, 0, SomeBytes.Lengt h);

              newStream.Close ();

              }

              else

              {

              req.ContentLeng th = 0;

              }

              result = (HttpWebRespons e) req.GetResponse ();

              Stream ReceiveStream = result.GetRespo nseStream();

              Encoding encode = System.Text.Enc oding.GetEncodi ng("utf-8");

              StreamReader sr = new StreamReader( ReceiveStream, encode );

              Char[] read = new Char[256];

              int count = sr.Read( read, 0, 256 );

              while (count > 0)

              {

              tempStr = new String(read, 0, count);

              retStr += tempStr;

              count = sr.Read(read, 0, 256);

              }

              retStr.Trim();

              }

              catch (Exception e)

              {

              retStr = "Error!!";

              }

              finally

              {

              if ( result != null )

              {

              result.Close();

              }

              }

              return retStr;

              }



              Comment

              • Justin Rogers

                #8
                Re: HTTPS with WebResponse class

                Best way to test your client is see if you can do the same from IE. Most of
                the System.Net classes take configuration from IE behind the scenes. If it
                doesn't work in IE and you do get it working, make sure to close all
                instances of IE so the data persists before re-running the .NET application.
                Some changes are considered dynamic and won't be written to the registry
                until close.

                Hopefully you find that IE won't connect either. I find it hard to believe
                that .NET would have a more stringent implementation of SSL than IE. But it
                is possible.

                --
                Justin Rogers
                DigiTec Web Consultants, LLC.

                "Aung" <aung@aungkyawm oe_NOSPAM_.net> wrote in message
                news:ezn5SNnbDH A.1580@tk2msftn gp13.phx.gbl...[color=blue]
                > Hello,
                >
                > I am having a problem with WebRequest class. I used the following code to
                > post some data to a page and retrive back the response. It works fine with
                > http:// connection. When i use that with https:// connection, it thrown an
                > exception "The underlying connection was closed: Could not establish trust
                > relationship with remote server.". I am using self sign certificate on the
                > web server and the root and CA certificates are installed on the client
                > machine using the following code.
                >
                > your suggestions will be great appreciated.
                >
                > Aung
                >
                > public string postForm(string url, string postData)
                >
                > {
                >
                > string retStr="", tempStr;
                >
                > HttpWebResponse result = null;
                >
                > try
                >
                > {
                >
                > HttpWebRequest req = (HttpWebRequest ) WebRequest.Crea te(url);
                >
                > req.Method = "POST";
                >
                > req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET[/color]
                CLR[color=blue]
                > 1.0.3705)";
                >
                > req.ContentType = "applicatio n/x-www-form-urlencoded";
                >
                > StringBuilder UrlEncoded = new StringBuilder() ;
                >
                > Char[] reserved = {'?', '=', '&'};
                >
                > byte[] SomeBytes = null;
                >
                > if (postData != null)
                >
                > {
                >
                > int i=0, j;
                >
                > while(i<postDat a.Length)
                >
                > {
                >
                > j=postData.Inde xOfAny(reserved , i);
                >
                > if (j==-1)
                >
                > {
                >
                > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i ,
                > postData.Length-i)));
                >
                > break;
                >
                > }
                >
                > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i , j-i)));
                >
                > UrlEncoded.Appe nd(postData.Sub string(j,1));
                >
                > i = j+1;
                >
                > }
                >
                > SomeBytes = Encoding.UTF8.G etBytes(UrlEnco ded.ToString()) ;
                >
                > req.ContentLeng th = SomeBytes.Lengt h;
                >
                > Stream newStream = req.GetRequestS tream();
                >
                > newStream.Write (SomeBytes, 0, SomeBytes.Lengt h);
                >
                > newStream.Close ();
                >
                > }
                >
                > else
                >
                > {
                >
                > req.ContentLeng th = 0;
                >
                > }
                >
                > result = (HttpWebRespons e) req.GetResponse ();
                >
                > Stream ReceiveStream = result.GetRespo nseStream();
                >
                > Encoding encode = System.Text.Enc oding.GetEncodi ng("utf-8");
                >
                > StreamReader sr = new StreamReader( ReceiveStream, encode );
                >
                > Char[] read = new Char[256];
                >
                > int count = sr.Read( read, 0, 256 );
                >
                > while (count > 0)
                >
                > {
                >
                > tempStr = new String(read, 0, count);
                >
                > retStr += tempStr;
                >
                > count = sr.Read(read, 0, 256);
                >
                > }
                >
                > retStr.Trim();
                >
                > }
                >
                > catch (Exception e)
                >
                > {
                >
                > retStr = "Error!!";
                >
                > }
                >
                > finally
                >
                > {
                >
                > if ( result != null )
                >
                > {
                >
                > result.Close();
                >
                > }
                >
                > }
                >
                > return retStr;
                >
                > }
                >
                >
                >[/color]


                Comment

                • Joe Kaplan \(MVP - ADSI\)

                  #9
                  Re: HTTPS with WebResponse class

                  A thing that I have found that can help is to implement a class based on
                  ICertificatePol icy that handles the CheckValidation Result method. If you
                  set an instance of your class to the ServicePointMan ager.Certificat ePolicy
                  property, you can override the behavior of certificate handling errors.
                  Returning true will cause the system to ignore all errors, which is
                  sometimes helpful for testing (but a bad a idea for production code).

                  HTH,

                  Joe K.

                  "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                  news:%238bt4Ynb DHA.2572@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                  > Best way to test your client is see if you can do the same from IE. Most[/color]
                  of[color=blue]
                  > the System.Net classes take configuration from IE behind the scenes. If[/color]
                  it[color=blue]
                  > doesn't work in IE and you do get it working, make sure to close all
                  > instances of IE so the data persists before re-running the .NET[/color]
                  application.[color=blue]
                  > Some changes are considered dynamic and won't be written to the registry
                  > until close.
                  >
                  > Hopefully you find that IE won't connect either. I find it hard to[/color]
                  believe[color=blue]
                  > that .NET would have a more stringent implementation of SSL than IE. But[/color]
                  it[color=blue]
                  > is possible.
                  >
                  > --
                  > Justin Rogers
                  > DigiTec Web Consultants, LLC.
                  >
                  > "Aung" <aung@aungkyawm oe_NOSPAM_.net> wrote in message
                  > news:ezn5SNnbDH A.1580@tk2msftn gp13.phx.gbl...[color=green]
                  > > Hello,
                  > >
                  > > I am having a problem with WebRequest class. I used the following code[/color][/color]
                  to[color=blue][color=green]
                  > > post some data to a page and retrive back the response. It works fine[/color][/color]
                  with[color=blue][color=green]
                  > > http:// connection. When i use that with https:// connection, it thrown[/color][/color]
                  an[color=blue][color=green]
                  > > exception "The underlying connection was closed: Could not establish[/color][/color]
                  trust[color=blue][color=green]
                  > > relationship with remote server.". I am using self sign certificate on[/color][/color]
                  the[color=blue][color=green]
                  > > web server and the root and CA certificates are installed on the client
                  > > machine using the following code.
                  > >
                  > > your suggestions will be great appreciated.
                  > >
                  > > Aung
                  > >
                  > > public string postForm(string url, string postData)
                  > >
                  > > {
                  > >
                  > > string retStr="", tempStr;
                  > >
                  > > HttpWebResponse result = null;
                  > >
                  > > try
                  > >
                  > > {
                  > >
                  > > HttpWebRequest req = (HttpWebRequest ) WebRequest.Crea te(url);
                  > >
                  > > req.Method = "POST";
                  > >
                  > > req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET[/color]
                  > CLR[color=green]
                  > > 1.0.3705)";
                  > >
                  > > req.ContentType = "applicatio n/x-www-form-urlencoded";
                  > >
                  > > StringBuilder UrlEncoded = new StringBuilder() ;
                  > >
                  > > Char[] reserved = {'?', '=', '&'};
                  > >
                  > > byte[] SomeBytes = null;
                  > >
                  > > if (postData != null)
                  > >
                  > > {
                  > >
                  > > int i=0, j;
                  > >
                  > > while(i<postDat a.Length)
                  > >
                  > > {
                  > >
                  > > j=postData.Inde xOfAny(reserved , i);
                  > >
                  > > if (j==-1)
                  > >
                  > > {
                  > >
                  > > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i ,
                  > > postData.Length-i)));
                  > >
                  > > break;
                  > >
                  > > }
                  > >
                  > > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i , j-i)));
                  > >
                  > > UrlEncoded.Appe nd(postData.Sub string(j,1));
                  > >
                  > > i = j+1;
                  > >
                  > > }
                  > >
                  > > SomeBytes = Encoding.UTF8.G etBytes(UrlEnco ded.ToString()) ;
                  > >
                  > > req.ContentLeng th = SomeBytes.Lengt h;
                  > >
                  > > Stream newStream = req.GetRequestS tream();
                  > >
                  > > newStream.Write (SomeBytes, 0, SomeBytes.Lengt h);
                  > >
                  > > newStream.Close ();
                  > >
                  > > }
                  > >
                  > > else
                  > >
                  > > {
                  > >
                  > > req.ContentLeng th = 0;
                  > >
                  > > }
                  > >
                  > > result = (HttpWebRespons e) req.GetResponse ();
                  > >
                  > > Stream ReceiveStream = result.GetRespo nseStream();
                  > >
                  > > Encoding encode = System.Text.Enc oding.GetEncodi ng("utf-8");
                  > >
                  > > StreamReader sr = new StreamReader( ReceiveStream, encode );
                  > >
                  > > Char[] read = new Char[256];
                  > >
                  > > int count = sr.Read( read, 0, 256 );
                  > >
                  > > while (count > 0)
                  > >
                  > > {
                  > >
                  > > tempStr = new String(read, 0, count);
                  > >
                  > > retStr += tempStr;
                  > >
                  > > count = sr.Read(read, 0, 256);
                  > >
                  > > }
                  > >
                  > > retStr.Trim();
                  > >
                  > > }
                  > >
                  > > catch (Exception e)
                  > >
                  > > {
                  > >
                  > > retStr = "Error!!";
                  > >
                  > > }
                  > >
                  > > finally
                  > >
                  > > {
                  > >
                  > > if ( result != null )
                  > >
                  > > {
                  > >
                  > > result.Close();
                  > >
                  > > }
                  > >
                  > > }
                  > >
                  > > return retStr;
                  > >
                  > > }
                  > >
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Drebin

                    #10
                    Re: HTTPS with WebResponse class

                    Egads!! BAD cross-poster - BAD!!

                    Anyhow, yes - this is exactly what the problem is. You can't programatically
                    specify a trust list (at least I haven't run across a way) - so even if you
                    log in with that account, and add the certificate authority -
                    programatically - it will still not trust that CA.

                    The ONLY way I've seen this or been able to get this to work (because I
                    needed to do the same thing) - is you have to get real certificates, like
                    from Verisign or Thawte..


                    "Aung" <aung@aungkyawm oe_NOSPAM_.net> wrote in message
                    news:u7xxlOobDH A.3896@TK2MSFTN GP11.phx.gbl...[color=blue]
                    > Yes. i used IE before calling from my application. IE popup with a warning
                    > message telling me that "certificat e on the server is not the same name[/color]
                    bla[color=blue]
                    > bla. " and when i hit OK, i can view the SSL page with form.
                    >
                    > my .NET application cannot.
                    >
                    >
                    > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                    > news:#8bt4YnbDH A.2572@TK2MSFTN GP12.phx.gbl...[color=green]
                    > > Best way to test your client is see if you can do the same from IE.[/color][/color]
                    Most[color=blue]
                    > of[color=green]
                    > > the System.Net classes take configuration from IE behind the scenes. If[/color]
                    > it[color=green]
                    > > doesn't work in IE and you do get it working, make sure to close all
                    > > instances of IE so the data persists before re-running the .NET[/color]
                    > application.[color=green]
                    > > Some changes are considered dynamic and won't be written to the registry
                    > > until close.
                    > >
                    > > Hopefully you find that IE won't connect either. I find it hard to[/color]
                    > believe[color=green]
                    > > that .NET would have a more stringent implementation of SSL than IE.[/color][/color]
                    But[color=blue]
                    > it[color=green]
                    > > is possible.
                    > >
                    > > --
                    > > Justin Rogers
                    > > DigiTec Web Consultants, LLC.
                    > >
                    > > "Aung" <aung@aungkyawm oe_NOSPAM_.net> wrote in message
                    > > news:ezn5SNnbDH A.1580@tk2msftn gp13.phx.gbl...[color=darkred]
                    > > > Hello,
                    > > >
                    > > > I am having a problem with WebRequest class. I used the following code[/color][/color]
                    > to[color=green][color=darkred]
                    > > > post some data to a page and retrive back the response. It works fine[/color][/color]
                    > with[color=green][color=darkred]
                    > > > http:// connection. When i use that with https:// connection, it[/color][/color][/color]
                    thrown[color=blue]
                    > an[color=green][color=darkred]
                    > > > exception "The underlying connection was closed: Could not establish[/color][/color]
                    > trust[color=green][color=darkred]
                    > > > relationship with remote server.". I am using self sign certificate on[/color][/color]
                    > the[color=green][color=darkred]
                    > > > web server and the root and CA certificates are installed on the[/color][/color][/color]
                    client[color=blue][color=green][color=darkred]
                    > > > machine using the following code.
                    > > >
                    > > > your suggestions will be great appreciated.
                    > > >
                    > > > Aung
                    > > >
                    > > > public string postForm(string url, string postData)
                    > > >
                    > > > {
                    > > >
                    > > > string retStr="", tempStr;
                    > > >
                    > > > HttpWebResponse result = null;
                    > > >
                    > > > try
                    > > >
                    > > > {
                    > > >
                    > > > HttpWebRequest req = (HttpWebRequest ) WebRequest.Crea te(url);
                    > > >
                    > > > req.Method = "POST";
                    > > >
                    > > > req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;[/color][/color][/color]
                    ..NET[color=blue][color=green]
                    > > CLR[color=darkred]
                    > > > 1.0.3705)";
                    > > >
                    > > > req.ContentType = "applicatio n/x-www-form-urlencoded";
                    > > >
                    > > > StringBuilder UrlEncoded = new StringBuilder() ;
                    > > >
                    > > > Char[] reserved = {'?', '=', '&'};
                    > > >
                    > > > byte[] SomeBytes = null;
                    > > >
                    > > > if (postData != null)
                    > > >
                    > > > {
                    > > >
                    > > > int i=0, j;
                    > > >
                    > > > while(i<postDat a.Length)
                    > > >
                    > > > {
                    > > >
                    > > > j=postData.Inde xOfAny(reserved , i);
                    > > >
                    > > > if (j==-1)
                    > > >
                    > > > {
                    > > >
                    > > > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i ,
                    > > > postData.Length-i)));
                    > > >
                    > > > break;
                    > > >
                    > > > }
                    > > >
                    > > > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i , j-i)));
                    > > >
                    > > > UrlEncoded.Appe nd(postData.Sub string(j,1));
                    > > >
                    > > > i = j+1;
                    > > >
                    > > > }
                    > > >
                    > > > SomeBytes = Encoding.UTF8.G etBytes(UrlEnco ded.ToString()) ;
                    > > >
                    > > > req.ContentLeng th = SomeBytes.Lengt h;
                    > > >
                    > > > Stream newStream = req.GetRequestS tream();
                    > > >
                    > > > newStream.Write (SomeBytes, 0, SomeBytes.Lengt h);
                    > > >
                    > > > newStream.Close ();
                    > > >
                    > > > }
                    > > >
                    > > > else
                    > > >
                    > > > {
                    > > >
                    > > > req.ContentLeng th = 0;
                    > > >
                    > > > }
                    > > >
                    > > > result = (HttpWebRespons e) req.GetResponse ();
                    > > >
                    > > > Stream ReceiveStream = result.GetRespo nseStream();
                    > > >
                    > > > Encoding encode = System.Text.Enc oding.GetEncodi ng("utf-8");
                    > > >
                    > > > StreamReader sr = new StreamReader( ReceiveStream, encode );
                    > > >
                    > > > Char[] read = new Char[256];
                    > > >
                    > > > int count = sr.Read( read, 0, 256 );
                    > > >
                    > > > while (count > 0)
                    > > >
                    > > > {
                    > > >
                    > > > tempStr = new String(read, 0, count);
                    > > >
                    > > > retStr += tempStr;
                    > > >
                    > > > count = sr.Read(read, 0, 256);
                    > > >
                    > > > }
                    > > >
                    > > > retStr.Trim();
                    > > >
                    > > > }
                    > > >
                    > > > catch (Exception e)
                    > > >
                    > > > {
                    > > >
                    > > > retStr = "Error!!";
                    > > >
                    > > > }
                    > > >
                    > > > finally
                    > > >
                    > > > {
                    > > >
                    > > > if ( result != null )
                    > > >
                    > > > {
                    > > >
                    > > > result.Close();
                    > > >
                    > > > }
                    > > >
                    > > > }
                    > > >
                    > > > return retStr;
                    > > >
                    > > > }
                    > > >
                    > > >
                    > > >[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • Tim Cartwright

                      #11
                      Re: HTTPS with WebResponse class

                      I was having the same issue using a MS Certificate Server . If you are using
                      you
                      own certificate authority to issue the certificate the problem lies in the
                      fact
                      that your client computer does not trust the issuing certificate authority.
                      Read
                      the section "Install Your Certification Authority's Certificate on the
                      Client"
                      from http://support.microsoft.com/default...b;en-us;324284 IE gives
                      you
                      the option to accept this discrepancy, but .net does not.

                      Tim Cartwright //Will write code for food


                      "Drebin" <tRhEeMdOrVeEbi n@hotmail.com> wrote in message
                      news:ZIS3b.2862 $uS6.2766@newss vr31.news.prodi gy.com...[color=blue]
                      > Egads!! BAD cross-poster - BAD!!
                      >
                      > Anyhow, yes - this is exactly what the problem is. You can't[/color]
                      programatically[color=blue]
                      > specify a trust list (at least I haven't run across a way) - so even if[/color]
                      you[color=blue]
                      > log in with that account, and add the certificate authority -
                      > programatically - it will still not trust that CA.
                      >
                      > The ONLY way I've seen this or been able to get this to work (because I
                      > needed to do the same thing) - is you have to get real certificates, like
                      > from Verisign or Thawte..
                      >
                      >
                      > "Aung" <aung@aungkyawm oe_NOSPAM_.net> wrote in message
                      > news:u7xxlOobDH A.3896@TK2MSFTN GP11.phx.gbl...[color=green]
                      > > Yes. i used IE before calling from my application. IE popup with a[/color][/color]
                      warning[color=blue][color=green]
                      > > message telling me that "certificat e on the server is not the same name[/color]
                      > bla[color=green]
                      > > bla. " and when i hit OK, i can view the SSL page with form.
                      > >
                      > > my .NET application cannot.
                      > >
                      > >
                      > > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                      > > news:#8bt4YnbDH A.2572@TK2MSFTN GP12.phx.gbl...[color=darkred]
                      > > > Best way to test your client is see if you can do the same from IE.[/color][/color]
                      > Most[color=green]
                      > > of[color=darkred]
                      > > > the System.Net classes take configuration from IE behind the scenes.[/color][/color][/color]
                      If[color=blue][color=green]
                      > > it[color=darkred]
                      > > > doesn't work in IE and you do get it working, make sure to close all
                      > > > instances of IE so the data persists before re-running the .NET[/color]
                      > > application.[color=darkred]
                      > > > Some changes are considered dynamic and won't be written to the[/color][/color][/color]
                      registry[color=blue][color=green][color=darkred]
                      > > > until close.
                      > > >
                      > > > Hopefully you find that IE won't connect either. I find it hard to[/color]
                      > > believe[color=darkred]
                      > > > that .NET would have a more stringent implementation of SSL than IE.[/color][/color]
                      > But[color=green]
                      > > it[color=darkred]
                      > > > is possible.
                      > > >
                      > > > --
                      > > > Justin Rogers
                      > > > DigiTec Web Consultants, LLC.
                      > > >
                      > > > "Aung" <aung@aungkyawm oe_NOSPAM_.net> wrote in message
                      > > > news:ezn5SNnbDH A.1580@tk2msftn gp13.phx.gbl...
                      > > > > Hello,
                      > > > >
                      > > > > I am having a problem with WebRequest class. I used the following[/color][/color][/color]
                      code[color=blue][color=green]
                      > > to[color=darkred]
                      > > > > post some data to a page and retrive back the response. It works[/color][/color][/color]
                      fine[color=blue][color=green]
                      > > with[color=darkred]
                      > > > > http:// connection. When i use that with https:// connection, it[/color][/color]
                      > thrown[color=green]
                      > > an[color=darkred]
                      > > > > exception "The underlying connection was closed: Could not establish[/color]
                      > > trust[color=darkred]
                      > > > > relationship with remote server.". I am using self sign certificate[/color][/color][/color]
                      on[color=blue][color=green]
                      > > the[color=darkred]
                      > > > > web server and the root and CA certificates are installed on the[/color][/color]
                      > client[color=green][color=darkred]
                      > > > > machine using the following code.
                      > > > >
                      > > > > your suggestions will be great appreciated.
                      > > > >
                      > > > > Aung
                      > > > >
                      > > > > public string postForm(string url, string postData)
                      > > > >
                      > > > > {
                      > > > >
                      > > > > string retStr="", tempStr;
                      > > > >
                      > > > > HttpWebResponse result = null;
                      > > > >
                      > > > > try
                      > > > >
                      > > > > {
                      > > > >
                      > > > > HttpWebRequest req = (HttpWebRequest ) WebRequest.Crea te(url);
                      > > > >
                      > > > > req.Method = "POST";
                      > > > >
                      > > > > req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;[/color][/color]
                      > .NET[color=green][color=darkred]
                      > > > CLR
                      > > > > 1.0.3705)";
                      > > > >
                      > > > > req.ContentType = "applicatio n/x-www-form-urlencoded";
                      > > > >
                      > > > > StringBuilder UrlEncoded = new StringBuilder() ;
                      > > > >
                      > > > > Char[] reserved = {'?', '=', '&'};
                      > > > >
                      > > > > byte[] SomeBytes = null;
                      > > > >
                      > > > > if (postData != null)
                      > > > >
                      > > > > {
                      > > > >
                      > > > > int i=0, j;
                      > > > >
                      > > > > while(i<postDat a.Length)
                      > > > >
                      > > > > {
                      > > > >
                      > > > > j=postData.Inde xOfAny(reserved , i);
                      > > > >
                      > > > > if (j==-1)
                      > > > >
                      > > > > {
                      > > > >
                      > > > > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i ,
                      > > > > postData.Length-i)));
                      > > > >
                      > > > > break;
                      > > > >
                      > > > > }
                      > > > >
                      > > > > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i ,[/color][/color][/color]
                      j-i)));[color=blue][color=green][color=darkred]
                      > > > >
                      > > > > UrlEncoded.Appe nd(postData.Sub string(j,1));
                      > > > >
                      > > > > i = j+1;
                      > > > >
                      > > > > }
                      > > > >
                      > > > > SomeBytes = Encoding.UTF8.G etBytes(UrlEnco ded.ToString()) ;
                      > > > >
                      > > > > req.ContentLeng th = SomeBytes.Lengt h;
                      > > > >
                      > > > > Stream newStream = req.GetRequestS tream();
                      > > > >
                      > > > > newStream.Write (SomeBytes, 0, SomeBytes.Lengt h);
                      > > > >
                      > > > > newStream.Close ();
                      > > > >
                      > > > > }
                      > > > >
                      > > > > else
                      > > > >
                      > > > > {
                      > > > >
                      > > > > req.ContentLeng th = 0;
                      > > > >
                      > > > > }
                      > > > >
                      > > > > result = (HttpWebRespons e) req.GetResponse ();
                      > > > >
                      > > > > Stream ReceiveStream = result.GetRespo nseStream();
                      > > > >
                      > > > > Encoding encode = System.Text.Enc oding.GetEncodi ng("utf-8");
                      > > > >
                      > > > > StreamReader sr = new StreamReader( ReceiveStream, encode );
                      > > > >
                      > > > > Char[] read = new Char[256];
                      > > > >
                      > > > > int count = sr.Read( read, 0, 256 );
                      > > > >
                      > > > > while (count > 0)
                      > > > >
                      > > > > {
                      > > > >
                      > > > > tempStr = new String(read, 0, count);
                      > > > >
                      > > > > retStr += tempStr;
                      > > > >
                      > > > > count = sr.Read(read, 0, 256);
                      > > > >
                      > > > > }
                      > > > >
                      > > > > retStr.Trim();
                      > > > >
                      > > > > }
                      > > > >
                      > > > > catch (Exception e)
                      > > > >
                      > > > > {
                      > > > >
                      > > > > retStr = "Error!!";
                      > > > >
                      > > > > }
                      > > > >
                      > > > > finally
                      > > > >
                      > > > > {
                      > > > >
                      > > > > if ( result != null )
                      > > > >
                      > > > > {
                      > > > >
                      > > > > result.Close();
                      > > > >
                      > > > > }
                      > > > >
                      > > > > }
                      > > > >
                      > > > > return retStr;
                      > > > >
                      > > > > }
                      > > > >
                      > > > >
                      > > > >
                      > > >
                      > > >[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • Joerg Jooss

                        #12
                        Re: HTTPS with WebResponse class

                        "Tim Cartwright" wrote:
                        [color=blue]
                        > I was having the same issue. If you are using you own certificate
                        > authority to
                        > issue the certificate the problem lise in the fact that your client
                        > computer does not trust the issuing certificate authority. Read the
                        > section "Install Your
                        > Certification Authority's Certificate on the Client" from
                        > http://support.microsoft.com/default...b;en-us;324284 IE
                        > gives you the
                        > option to accept this indescrepancy, but .net does not.[/color]

                        What about System.Net.ICer tificatePolicy? Isn't that what you want?

                        Cheers,
                        --
                        Joerg Jooss
                        joerg.jooss@gmx .net

                        Comment

                        • Franco Gustavo

                          #13
                          Re: HTTPS with WebResponse class

                          I was trying to do that a few months ago and I still need it.
                          I didn't resolve the problem, I have my own certificates.
                          May you show what you did?

                          Thanks,
                          Gustavo.


                          "Joe Kaplan (MVP - ADSI)" <joseph.e.kapla n@removethis.ac centure.com> wrote
                          in message news:eIC25znbDH A.2176@TK2MSFTN GP09.phx.gbl...[color=blue]
                          > A thing that I have found that can help is to implement a class based on
                          > ICertificatePol icy that handles the CheckValidation Result method. If you
                          > set an instance of your class to the ServicePointMan ager.Certificat ePolicy
                          > property, you can override the behavior of certificate handling errors.
                          > Returning true will cause the system to ignore all errors, which is
                          > sometimes helpful for testing (but a bad a idea for production code).
                          >
                          > HTH,
                          >
                          > Joe K.
                          >
                          > "Justin Rogers" <Justin@games4d otnet.com> wrote in message
                          > news:%238bt4Ynb DHA.2572@TK2MSF TNGP12.phx.gbl. ..[color=green]
                          > > Best way to test your client is see if you can do the same from IE.[/color][/color]
                          Most[color=blue]
                          > of[color=green]
                          > > the System.Net classes take configuration from IE behind the scenes. If[/color]
                          > it[color=green]
                          > > doesn't work in IE and you do get it working, make sure to close all
                          > > instances of IE so the data persists before re-running the .NET[/color]
                          > application.[color=green]
                          > > Some changes are considered dynamic and won't be written to the registry
                          > > until close.
                          > >
                          > > Hopefully you find that IE won't connect either. I find it hard to[/color]
                          > believe[color=green]
                          > > that .NET would have a more stringent implementation of SSL than IE.[/color][/color]
                          But[color=blue]
                          > it[color=green]
                          > > is possible.
                          > >
                          > > --
                          > > Justin Rogers
                          > > DigiTec Web Consultants, LLC.
                          > >
                          > > "Aung" <aung@aungkyawm oe_NOSPAM_.net> wrote in message
                          > > news:ezn5SNnbDH A.1580@tk2msftn gp13.phx.gbl...[color=darkred]
                          > > > Hello,
                          > > >
                          > > > I am having a problem with WebRequest class. I used the following code[/color][/color]
                          > to[color=green][color=darkred]
                          > > > post some data to a page and retrive back the response. It works fine[/color][/color]
                          > with[color=green][color=darkred]
                          > > > http:// connection. When i use that with https:// connection, it[/color][/color][/color]
                          thrown[color=blue]
                          > an[color=green][color=darkred]
                          > > > exception "The underlying connection was closed: Could not establish[/color][/color]
                          > trust[color=green][color=darkred]
                          > > > relationship with remote server.". I am using self sign certificate on[/color][/color]
                          > the[color=green][color=darkred]
                          > > > web server and the root and CA certificates are installed on the[/color][/color][/color]
                          client[color=blue][color=green][color=darkred]
                          > > > machine using the following code.
                          > > >
                          > > > your suggestions will be great appreciated.
                          > > >
                          > > > Aung
                          > > >
                          > > > public string postForm(string url, string postData)
                          > > >
                          > > > {
                          > > >
                          > > > string retStr="", tempStr;
                          > > >
                          > > > HttpWebResponse result = null;
                          > > >
                          > > > try
                          > > >
                          > > > {
                          > > >
                          > > > HttpWebRequest req = (HttpWebRequest ) WebRequest.Crea te(url);
                          > > >
                          > > > req.Method = "POST";
                          > > >
                          > > > req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;[/color][/color][/color]
                          ..NET[color=blue][color=green]
                          > > CLR[color=darkred]
                          > > > 1.0.3705)";
                          > > >
                          > > > req.ContentType = "applicatio n/x-www-form-urlencoded";
                          > > >
                          > > > StringBuilder UrlEncoded = new StringBuilder() ;
                          > > >
                          > > > Char[] reserved = {'?', '=', '&'};
                          > > >
                          > > > byte[] SomeBytes = null;
                          > > >
                          > > > if (postData != null)
                          > > >
                          > > > {
                          > > >
                          > > > int i=0, j;
                          > > >
                          > > > while(i<postDat a.Length)
                          > > >
                          > > > {
                          > > >
                          > > > j=postData.Inde xOfAny(reserved , i);
                          > > >
                          > > > if (j==-1)
                          > > >
                          > > > {
                          > > >
                          > > > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i ,
                          > > > postData.Length-i)));
                          > > >
                          > > > break;
                          > > >
                          > > > }
                          > > >
                          > > > UrlEncoded.Appe nd(HttpUtility. UrlEncode(postD ata.Substring(i , j-i)));
                          > > >
                          > > > UrlEncoded.Appe nd(postData.Sub string(j,1));
                          > > >
                          > > > i = j+1;
                          > > >
                          > > > }
                          > > >
                          > > > SomeBytes = Encoding.UTF8.G etBytes(UrlEnco ded.ToString()) ;
                          > > >
                          > > > req.ContentLeng th = SomeBytes.Lengt h;
                          > > >
                          > > > Stream newStream = req.GetRequestS tream();
                          > > >
                          > > > newStream.Write (SomeBytes, 0, SomeBytes.Lengt h);
                          > > >
                          > > > newStream.Close ();
                          > > >
                          > > > }
                          > > >
                          > > > else
                          > > >
                          > > > {
                          > > >
                          > > > req.ContentLeng th = 0;
                          > > >
                          > > > }
                          > > >
                          > > > result = (HttpWebRespons e) req.GetResponse ();
                          > > >
                          > > > Stream ReceiveStream = result.GetRespo nseStream();
                          > > >
                          > > > Encoding encode = System.Text.Enc oding.GetEncodi ng("utf-8");
                          > > >
                          > > > StreamReader sr = new StreamReader( ReceiveStream, encode );
                          > > >
                          > > > Char[] read = new Char[256];
                          > > >
                          > > > int count = sr.Read( read, 0, 256 );
                          > > >
                          > > > while (count > 0)
                          > > >
                          > > > {
                          > > >
                          > > > tempStr = new String(read, 0, count);
                          > > >
                          > > > retStr += tempStr;
                          > > >
                          > > > count = sr.Read(read, 0, 256);
                          > > >
                          > > > }
                          > > >
                          > > > retStr.Trim();
                          > > >
                          > > > }
                          > > >
                          > > > catch (Exception e)
                          > > >
                          > > > {
                          > > >
                          > > > retStr = "Error!!";
                          > > >
                          > > > }
                          > > >
                          > > > finally
                          > > >
                          > > > {
                          > > >
                          > > > if ( result != null )
                          > > >
                          > > > {
                          > > >
                          > > > result.Close();
                          > > >
                          > > > }
                          > > >
                          > > > }
                          > > >
                          > > > return retStr;
                          > > >
                          > > > }
                          > > >
                          > > >
                          > > >[/color]
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          Working...