Solved

ASP.NET Post to another website

Posted on 2011-03-13
1
295 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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