[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ASP.NET Post to another website

Posted on 2011-03-13
1
Medium Priority
?
306 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 2000 total points
ID: 35127076
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

656 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