conversion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ching-Lung

    #1

    conversion

    Hi,

    I have web browser control in my windows form and am
    implementing the following event:

    *************** *************** ***********
    public void BeforeNavigate( string URL, int Flags, string
    TargetFrameName , ref object PostData, string Headers, ref
    bool Cancel)
    *************** *************** ***********

    When I navigate on an htm file and submit the data (form
    with post method), what I see on PostData var is the
    bytes in System.Array.

    I tried the following code:

    *************** *************** ***********
    Stream s = (Stream)PostDat a;
    Byte[] read = new Byte[32];
    int bytes = s.Read(read, 0, read.Length);
    string str = Encoding.ASCII. GetString(b);
    MessageBox.Show (str);
    *************** *************** ***********

    But it complains that improper casting from object to
    stream.

    So, how do I convert this PostData to string in order to
    see the actual data?

    Please help. Thanks!
    -CL
  • Chris LaJoie

    #2
    Re: conversion

    I don't think you've posted the code that's required to determine the
    problem. What exactly is this PostData object that you're trying to cast
    into a stream? I think to determine your problem I would have to see
    several lines before this one:
    Stream s = (Stream)PostDat a;

    Chris LaJoie

    "Ching-Lung" <chinglung@alum ni.cs.utexas.ed u> wrote in message
    news:022101c363 6f$09c28ad0$a60 1280a@phx.gbl.. .[color=blue]
    > Hi,
    >
    > I have web browser control in my windows form and am
    > implementing the following event:
    >
    > *************** *************** ***********
    > public void BeforeNavigate( string URL, int Flags, string
    > TargetFrameName , ref object PostData, string Headers, ref
    > bool Cancel)
    > *************** *************** ***********
    >
    > When I navigate on an htm file and submit the data (form
    > with post method), what I see on PostData var is the
    > bytes in System.Array.
    >
    > I tried the following code:
    >
    > *************** *************** ***********
    > Stream s = (Stream)PostDat a;
    > Byte[] read = new Byte[32];
    > int bytes = s.Read(read, 0, read.Length);
    > string str = Encoding.ASCII. GetString(b);
    > MessageBox.Show (str);
    > *************** *************** ***********
    >
    > But it complains that improper casting from object to
    > stream.
    >
    > So, how do I convert this PostData to string in order to
    > see the actual data?
    >
    > Please help. Thanks!
    > -CL[/color]


    Comment

    • Ching-Lung

      #3
      Re: conversion

      PostData is one of the parameters of BeforeNavigate( )
      event that contains the form's data of the submitted HTM
      page via "post" method.

      This is the HTM page looks like:
      *************** *************** *************** **
      <html>
      <body>
      <form name="myForm" action="form1.h tm" method="post">
      <input type="text" name="myText" /><br/>
      <input type="submit" value="Submit" />
      </form>
      </body>
      </html>
      *************** *************** *************** **

      It basically contains a simple form with one input text
      area and a button. After clicking submit, web browser
      control raises the event BeforeNavigate( ) that one of its
      parameters, named "PostData", contains the actual data of
      the form.


      This is my original implementation of BeforeNavigate( )
      event:
      *************** *************** *************** **
      public void BeforeNavigate( string URL, int Flags, string
      TargetFrameName , ref object PostData, string Headers, ref
      bool Cancel)
      {
      if(PostData != null)
      {
      try
      {
      Stream s = (Stream)PostDat a;
      Byte[] read = new Byte[32];
      int bytes = s.Read(read, 0, read.Length);

      while(bytes > 0)
      {
      String str = Encoding.ASCII. GetString(read) ;
      MessageBox.Show (str);
      bytes = s.Read(read, 0, read.Length);
      }
      }
      catch(Exception ex)
      {
      MessageBox.Show (ex.Message);
      }
      }
      }
      *************** *************** *************** **

      Every time I run this code, it will complain on
      line: "Stream s = (Stream)PostDat a;", throwing
      exception: "Specified cast is not valid."

      I tried to put a break point on that line and when it
      breaks, I see that "PostData" parameter is {System.Array}
      that contains 25 elements with type "byte".

      So, go back to my original question, how do I convert
      this "PostData" parameter to a readable string?

      Thanks.
      -CL



      [color=blue]
      >-----Original Message-----
      >I don't think you've posted the code that's required to[/color]
      determine the[color=blue]
      >problem. What exactly is this PostData object that[/color]
      you're trying to cast[color=blue]
      >into a stream? I think to determine your problem I would[/color]
      have to see[color=blue]
      >several lines before this one:
      >Stream s = (Stream)PostDat a;
      >
      >Chris LaJoie
      >
      >"Ching-Lung" <chinglung@alum ni.cs.utexas.ed u> wrote in[/color]
      message[color=blue]
      >news:022101c36 36f$09c28ad0$a6 01280a@phx.gbl. ..[color=green]
      >> Hi,
      >>
      >> I have web browser control in my windows form and am
      >> implementing the following event:
      >>
      >> *************** *************** ***********
      >> public void BeforeNavigate( string URL, int Flags, string
      >> TargetFrameName , ref object PostData, string Headers,[/color][/color]
      ref[color=blue][color=green]
      >> bool Cancel)
      >> *************** *************** ***********
      >>
      >> When I navigate on an htm file and submit the data (form
      >> with post method), what I see on PostData var is the
      >> bytes in System.Array.
      >>
      >> I tried the following code:
      >>
      >> *************** *************** ***********
      >> Stream s = (Stream)PostDat a;
      >> Byte[] read = new Byte[32];
      >> int bytes = s.Read(read, 0, read.Length);
      >> string str = Encoding.ASCII. GetString(b);
      >> MessageBox.Show (str);
      >> *************** *************** ***********
      >>
      >> But it complains that improper casting from object to
      >> stream.
      >>
      >> So, how do I convert this PostData to string in order to
      >> see the actual data?
      >>
      >> Please help. Thanks!
      >> -CL[/color]
      >
      >
      >.
      >[/color]

      Comment

      • Ching-Lung

        #4
        Re: conversion

        Cool, thx!

        -CL

        [color=blue]
        >-----Original Message-----
        >Sorry about that, I missed that in your first post.
        >
        >have a look here:
        >http://msdn.microsoft.com/library/default.asp?[/color]
        url=/workshop/browser/webbrowser/reference/events/beforenav
        igate.asp[color=blue]
        >
        >that url will probably wrap, just piece it together again[/color]
        in your browser.[color=blue]
        >
        >PostData is variant, so it could potentially be any type[/color]
        of data. I don't[color=blue]
        >believe a Stream can handle that (I must admit I haven't[/color]
        worked with Streams[color=blue]
        >much). Instead of casting it to a Stream, try casting it[/color]
        directly to a[color=blue]
        >string instead, and see what happens. If that doesn't[/color]
        work, can you put a[color=blue]
        >watch on the PostData object and view it in the watches[/color]
        window when you're[color=blue]
        >debugging? That might be able to tell you what type of[/color]
        data it is.[color=blue]
        >
        >
        >Hope this helps,
        >Chris LaJoie[/color]

        Comment

        • Jeffrey Tan[MSFT]

          #5
          Re: conversion


          Hi Ching,

          Yes, I think you should cast PostData parameter to System.String class then
          you can
          use the method of string class to process postdata parameter.

          Jeffrey Tan
          Microsoft Online Partner Support
          Get Secure! - www.microsoft.com/security
          This posting is provided "as is" with no warranties and confers no rights.

          --------------------
          | Content-Class: urn:content-classes:message
          | From: "Ching-Lung" <chinglung@alum ni.cs.utexas.ed u>
          | Sender: "Ching-Lung" <chinglung@alum ni.cs.utexas.ed u>
          | References: <022101c3636f$0 9c28ad0$a601280 a@phx.gbl>
          <en$lDS3YDHA.10 96@tk2msftngp13 .phx.gbl>
          | Subject: Re: conversion
          | Date: Fri, 15 Aug 2003 15:12:57 -0700
          | Lines: 123
          | Message-ID: <031f01c3637a$6 1c53560$a501280 a@phx.gbl>
          | MIME-Version: 1.0
          | Content-Type: text/plain;
          | charset="iso-8859-1"
          | Content-Transfer-Encoding: 7bit
          | X-Newsreader: Microsoft CDO for Windows 2000
          | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
          | Thread-Index: AcNjemHFBo3nqia MQfm8vVoeJRVgLg ==
          | Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
          | Path: cpmsftngxa06.ph x.gbl
          | Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1767 97
          | NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
          | X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
          |
          | PostData is one of the parameters of BeforeNavigate( )
          | event that contains the form's data of the submitted HTM
          | page via "post" method.
          |
          | This is the HTM page looks like:
          | *************** *************** *************** **
          | <html>
          | <body>
          | <form name="myForm" action="form1.h tm" method="post">
          | <input type="text" name="myText" /><br/>
          | <input type="submit" value="Submit" />
          | </form>
          | </body>
          | </html>
          | *************** *************** *************** **
          |
          | It basically contains a simple form with one input text
          | area and a button. After clicking submit, web browser
          | control raises the event BeforeNavigate( ) that one of its
          | parameters, named "PostData", contains the actual data of
          | the form.
          |
          |
          | This is my original implementation of BeforeNavigate( )
          | event:
          | *************** *************** *************** **
          | public void BeforeNavigate( string URL, int Flags, string
          | TargetFrameName , ref object PostData, string Headers, ref
          | bool Cancel)
          | {
          | if(PostData != null)
          | {
          | try
          | {
          | Stream s = (Stream)PostDat a;
          | Byte[] read = new Byte[32];
          | int bytes = s.Read(read, 0, read.Length);
          |
          | while(bytes > 0)
          | {
          | String str = Encoding.ASCII. GetString(read) ;
          | MessageBox.Show (str);
          | bytes = s.Read(read, 0, read.Length);
          | }
          | }
          | catch(Exception ex)
          | {
          | MessageBox.Show (ex.Message);
          | }
          | }
          | }
          | *************** *************** *************** **
          |
          | Every time I run this code, it will complain on
          | line: "Stream s = (Stream)PostDat a;", throwing
          | exception: "Specified cast is not valid."
          |
          | I tried to put a break point on that line and when it
          | breaks, I see that "PostData" parameter is {System.Array}
          | that contains 25 elements with type "byte".
          |
          | So, go back to my original question, how do I convert
          | this "PostData" parameter to a readable string?
          |
          | Thanks.
          | -CL
          |
          |
          |
          |
          | >-----Original Message-----
          | >I don't think you've posted the code that's required to
          | determine the
          | >problem. What exactly is this PostData object that
          | you're trying to cast
          | >into a stream? I think to determine your problem I would
          | have to see
          | >several lines before this one:
          | >Stream s = (Stream)PostDat a;
          | >
          | >Chris LaJoie
          | >
          | >"Ching-Lung" <chinglung@alum ni.cs.utexas.ed u> wrote in
          | message
          | >news:022101c36 36f$09c28ad0$a6 01280a@phx.gbl. ..
          | >> Hi,
          | >>
          | >> I have web browser control in my windows form and am
          | >> implementing the following event:
          | >>
          | >> *************** *************** ***********
          | >> public void BeforeNavigate( string URL, int Flags, string
          | >> TargetFrameName , ref object PostData, string Headers,
          | ref
          | >> bool Cancel)
          | >> *************** *************** ***********
          | >>
          | >> When I navigate on an htm file and submit the data (form
          | >> with post method), what I see on PostData var is the
          | >> bytes in System.Array.
          | >>
          | >> I tried the following code:
          | >>
          | >> *************** *************** ***********
          | >> Stream s = (Stream)PostDat a;
          | >> Byte[] read = new Byte[32];
          | >> int bytes = s.Read(read, 0, read.Length);
          | >> string str = Encoding.ASCII. GetString(b);
          | >> MessageBox.Show (str);
          | >> *************** *************** ***********
          | >>
          | >> But it complains that improper casting from object to
          | >> stream.
          | >>
          | >> So, how do I convert this PostData to string in order to
          | >> see the actual data?
          | >>
          | >> Please help. Thanks!
          | >> -CL
          | >
          | >
          | >.
          | >
          |

          Comment

          Working...