Solved

ASP.NET Post to another website

Posted on 2011-03-13
1
297 Views
Last Modified: 2012-05-11
I am trying to create a screen scrape app that will post a parameter to this site http://dsbs.sba.gov/dsbs/search/dsp_dsbs.cfm and then write the response to my screen. Here is the app that I tried to complete but it is saying that session cookies are not enabled. Any help would be appreciated.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim poststring As String = [String].Format("CageCD={0}", "26895")
        ResponseResult.Text = "<hr/>" & GetResponseString("http://dsbs.sba.gov/dsbs/search/dsp_dsbs.cfm", poststring)
    End Sub
    Public Function GetResponseString(ByVal url As String, ByVal poststring As String) As [String]
        Dim httpRequest As HttpWebRequest = DirectCast(WebRequest.Create("http://dsbs.sba.gov/dsbs/search/dsp_dsbs.cfm"), HttpWebRequest)

        httpRequest.Method = "POST"
        httpRequest.ContentType = "application/x-www-form-urlencoded"

        Dim bytedata As Byte() = Encoding.UTF8.GetBytes(poststring)
        httpRequest.ContentLength = bytedata.Length

        Dim requestStream As Stream = httpRequest.GetRequestStream()
        requestStream.Write(bytedata, 0, bytedata.Length)
        requestStream.Close()


        Dim httpWebResponse As HttpWebResponse = DirectCast(httpRequest.GetResponse(), HttpWebResponse)
        Dim responseStream As Stream = httpWebResponse.GetResponseStream()

        Dim sb As New StringBuilder()

        Using reader As New StreamReader(responseStream, System.Text.Encoding.UTF8)
            Dim line As String
            While (InlineAssignHelper(line, reader.ReadLine())) IsNot Nothing
                sb.Append(line)
            End While
        End Using

        Return sb.ToString()

    End Function
    Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
        target = value
        Return value
    End Function

Open in new window

0
Comment
Question by:jimseiwert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 35127076
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question