C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 307,175 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,534 people online right now. Registration is fast and FREE... Join Now!




Creating customized browser

 

Creating customized browser

him1234

27 Jun, 2009 - 12:05 AM
Post #1

New D.I.C Head
*

Joined: 26 Jun, 2009
Posts: 1

CODE


private void button1_Click(object sender, EventArgs e)
        {

            string requestmethod = "POST";
            string postData = "username=testmember&pwd=web123";
            //The Byte Array that will be used for writing the data to the stream.
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            //The URL of the webpage to send the data to.
            string URL = "http://marketplace.plastopedia.com/login.php";

            //The type of content being send, this is almost always "application/x-www-form-urlencoded".
            string contenttype = "application/x-www-form-urlencoded";

            //What the server sends back:
            string responseFromServer = null;
            WebRequest request = WebRequest.Create(URL);

            //We also need a Stream:
            Stream dataStream;

            //...And a webResponce,
            WebResponse response;

            //don't forget the streamreader either!
            StreamReader reader; //We will need to set the method used to send the data.
            request.Method = requestmethod;

            //Then the contenttype:
            request.ContentType = contenttype;

            //content length
            request.ContentLength = byteArray.Length;

            //ok, now get the request from the webRequest object, and put it into our Stream:
            dataStream = request.GetRequestStream();

            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);

            // Close the Stream object.
            dataStream.Close();
            response = request.GetResponse();

            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();

            //Open the responce stream:
            reader = new StreamReader(dataStream);

            //read the content into the responcefromserver string
            responseFromServer = reader.ReadToEnd();

            // Clean up the streams.
            reader.Close();
            dataStream.Close();
            response.Close();


            //Now, display the responce!
            Console.WriteLine(responseFromServer);


Problem: How can we use the content of the string "responseFromServer" to open/show the php web page????

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 3)

firebolt

RE: Creating Customized Browser

27 Jun, 2009 - 12:51 AM
Post #2

D.I.C Lover
Group Icon

Joined: 20 Feb, 2009
Posts: 5,476



Thanked: 77 times
Dream Kudos: 1675
My Contributions
Please ask this in the appropriate language forum, found on the left of screen.
User is online!Profile CardPM
+Quote Post

Mullins

RE: Creating Customized Browser

27 Jun, 2009 - 04:30 AM
Post #3

New D.I.C Head
*

Joined: 19 Jun, 2009
Posts: 10

QUOTE
php web page????


You'll only get HTML returned. The server processes the PHP first, then throws HTML at you.
User is offlineProfile CardPM
+Quote Post

masteryee

RE: Creating Customized Browser

27 Jun, 2009 - 11:23 PM
Post #4

D.I.C Regular
***

Joined: 16 May, 2009
Posts: 269



Thanked: 38 times
My Contributions
You need to use a WebBrowser component to render the HTML string. I used a WebBrowser control on my form, and the variable name is webBrowser1:

csharp

WebRequest request = WebRequest.Create(@"http://www.dreamincode.net");
WebResponse response = request.GetResponse();
webBrowser1.DocumentStream = response.GetResponseStream();


This only lets you view the HTML as a web page...I don't think you can actually navigate any links on the page.

If you need to be able to navigate the web page (i.e. click on links), then you should just use a WebBrowser control instead of the WebRequest/WebResponse classes, and look into using the System.Net.NetworkCredential and/or the WebClient class to handle the login credentials. If memory servers me right, there's a thread in the C# forum that talks about this sometime within the past month....
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:20PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month