HttpWebRequest submit. Yeah, you've seen this before but this is different...

Joined
Oct 29, 2008
Messages
1
Reaction score
0
I've read MANY posts about this subject but my situation, at least to me, appears to be different.

I'm attempting to autosubmit a page that uses GET and has hidden text fields. I don't know if there's a big difference between GET and POST for this kinda thing but I'm unable to make it work. More importantly, I am simply trying to send x number of requests in a fixed amount of time (currently using timer). Basically, this is for an online game and I want to submit the page, let's say 5 times in 1 second.

I have both ContentType types below, with one commented out, depending on what I was testing at the time. POST seems to go with 'application', and GET seems to do the 'text/xml' thing.

For the request to take place I have to attempt to get a response, right? My understanding is that both parts are required to get the job done. Will using GET or POST really make a difference? My example has only 1 piece of data that needs to be sent to the 'someurl' webpage.

Anyway, so what's the best way to submit the required info?


Code:
Dim sValue As String = "test"
        Dim iRespCounter As Integer = 0
        Dim eA As New System.Text.ASCIIEncoding ' 
        Dim sb As New Text.StringBuilder

        sb.Append("value1=" & sValue)    
        Dim PostData As String = sb.ToString
        Dim data As Byte() = eA.GetBytes(PostData)

        Dim myRequest As HttpWebRequest = CType(WebRequest.Create("someURL"), HttpWebRequest)
        ' Dim myResponse As HttpWebResponse

        myRequest.Method = WebRequestMethods.Http.Post
        myRequest.ContentLength = data.Length
        myRequest.ContentType = "application/x-www-form-urlencoded" '"text/xml; encoding='utf-8'" '
        'myRequest.ContentType = "text/xml; encoding='utf-8'"

        [B]Dim newStream As Stream = myRequest.GetRequestStream[/B]
        newStream.Write(data, 0, data.Length)
        newStream.Close()

It seems that if I use method GET, I get an error "Cannot send a content-body with this verb-type" at the bold area. It seems that if I want to send info I need to use POST, but as I said, I'm assuming that when the page is submitted the server side simply does a request("fieldname").... Is there any way to automate this, or am I missing something?

Any help is appreciated!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top