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" <ch*******@alumni.cs.utexas.edu>
| Sender: "Ching-Lung" <ch*******@alumni.cs.utexas.edu>
| References: <02****************************@phx.gbl>
<en**************@tk2msftngp13.phx.gbl>
| Subject: Re: conversion
| Date: Fri, 15 Aug 2003 15:12:57 -0700
| Lines: 123
| Message-ID: <03****************************@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: AcNjemHFBo3nqiaMQfm8vVoeJRVgLg==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:176797
| NNTP-Posting-Host: TK2MSFTNGXA13 10.40.1.165
| X-Tomcat-NG: microsoft.public.dotnet.languages.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.htm" 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)PostData;
| 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)PostData;", 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)PostData;
| >
| >Chris LaJoie
| >
| >"Ching-Lung" <ch*******@alumni.cs.utexas.edu> wrote in
| message
| >news:02****************************@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)PostData;
| >> 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
| >
| >
| >.
| >
|