Solved

ASP.NET Post to another website

Posted on 2011-03-13
1
296 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
1 Comment
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 35127076
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 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