Solved

ASP.NET Post to another website

Posted on 2011-03-13
1
293 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
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now