Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 11th, 2006, 04:11 AM
Registered User
Join Date: Aug 2006
Location: mumbai, , India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTTPWebRespose Problem in ASP.net

Hello everybody

            I am developing a website in ASP.net.i have one htm page where the user enters the userid and password.on submitting the page i am redirecting it to an aspx page where in i am facin some problems.the ConnectServer.aspx page actully connects to a servlet on our server.I pass the username and password as parmeters to the servlet.the servlet validates the user and sends back some response.Now i am able to call the servlet properly using HTTPWebRequest.but i am having problems in capturing the Response from the Servlet using HTTPWebResponse.the problem is that when i click submit i am redirected to the ConnectServer.aspx page but i do not get any response displayed on my screen.I have used Response.write to see the response from servlet on the screen.however whe i refresh the page from i am able to view the data.i just dont knwo what the problem is.sometimes response is displayed and sometimes not.please help me.. i am also sending the code.please help coz its really urgent.

Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Data.OleDb

Partial Class ConnectServer
    Inherits System.Web.UI.Page
    Dim strparam As String
    Dim req As HttpWebRequest
    Dim resp As HttpWebResponse = Nothing
    Dim objStream As Stream
    Dim url As String
    Dim struser As String
    Dim strpwd As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        url= "url of sevlet"
        struser = Request.Form("txtusername")
        strpwd = Request.Form("txtpassword")
        Response.Write("Username is " + struser + "Password is " + strpwd)

        'Dim prxy As New WebProxy("", 8085)
        strparam = ("username=" & struser & "&password=" & strpwd)

        Dim encoding As New ASCIIEncoding()
        Dim enc = System.Text.Encoding.GetEncoding(1252)

        Dim byte1 As Byte() = encoding.GetBytes(strparam)

        req = WebRequest.Create(url)

        'req.Proxy = prxy
        req.Method = "POST"
        req.ContentLength = strparam.Length
        req.ContentType = "application/x-www-form-urlencoded"

            Dim newStream As Stream = req.GetRequestStream()
            newStream.Write(byte1, 0, byte1.Length)
            'Response.Write("The value of 'ContentLength' property after sending the data is {0}" + req.ContentLength)
        Catch ex As Exception
            Response.Write("Error in Request " & ex.Message.ToString())
        End Try

    End Sub

    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
            url = "url of servlet"
            req = WebRequest.Create(url)
            resp = CType(req.GetResponse(), HttpWebResponse)
            req.Method = "GET"
            req.ContentType = "application/x-www-form-urlencoded"

            If (resp.StatusCode <> HttpStatusCode.OK) Then
                Throw New Exception(Response.StatusCode.ToString())
            End If

            objStream = req.GetResponse.GetResponseStream()
            Dim objReader As New StreamReader(objStream)
            Dim sLine As String = ""
            Dim i As Integer = 0

            Do While Not sLine Is Nothing
                i += 1
                sLine = objReader.ReadLine
                If Not sLine Is Nothing Then
                    Response.Write("Response from Servlet " + sLine)
                End If

            sLine = Nothing

        Catch ex As Exception
            Response.Write("Error in Response " & ex.Message.ToString())
        End Try

            End Sub
End Class



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom HTTP 404 Problem w/ASP to ASP.NET kwilliams ASP.NET 2.0 Professional 7 November 26th, 2007 04:17 PM
Problem Converting C# to VB.NET in ASP.NET kwilliams ASP.NET 2.0 Basics 0 February 9th, 2007 06:22 PM
Problem with Exercise in Beg. asp.net for VB.net! mrfella71 BOOK: Beginning ASP.NET 1.0 1 October 23rd, 2005 12:06 PM
ASP.NET problem btls ASP.NET 1.0 and 1.1 Basics 1 July 19th, 2004 08:33 AM

All times are GMT -4. The time now is 08:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.