POST via HttpWebRequest not working. HELP! 
Author Message
 POST via HttpWebRequest not working. HELP!

Here's how I'm trying to POST a request via HttpWebRequest:

      If Request.Method = "POST" Then
         Form = zGetPostForm(ASPPack, Request)
                                               ' Don't worry about this
                                               ' returns a byte array
                                               ' of Form data (X=Y&A=B)
         If Not Form Is Nothing Then
            If Form.Length > 0 Then
               Request.ContentLength = Form.Length
               zPostForm(Form, Request) ' See method below
            End If
         End If
      End If

      Response = CType(Request.GetResponse, HttpWebResponse)

   Private Sub zPostForm(ByRef Form() As Byte, ByRef Request As
HttpWebRequest)

      Dim PostBody As System.IO.Stream

      If Form.Length > 0 Then
         PostBody = Request.GetRequestStream
         PostBody.Write(Form, 0, Form.Length)
         PostBody.Close()
      End If

   End Sub

Here's the HTTP info which comes across to the target ASPX script

<ALL_HTTP>HTTP_CONTENT_LENGTH:56
HTTP_COOKIE:FPSNOW=BRAD=Done; VANILLA=Yum; CHOCOLATE=CHIP1=Yum&CHIP2=YumYum!
HTTP_EXPECT:100-continue
HTTP_HOST:localhost
HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461;
.NET CLR 1.0.3705) [BOA.NET]
</ALL_HTTP>

So you see the content length came across, as well as a new HTTP_EXPECT,
which I've never seen before so something's happening. however, the Form is
empty! context.Request.Form.Count = 0.

What am I missing?

Thanks,
--

Joseph Geretz



Tue, 01 Feb 2005 22:50:05 GMT  
 POST via HttpWebRequest not working. HELP!
This was all that was missing

Request.ContentType = "application/x-www-form-urlencoded"

Cool! Thanks to Peter Brunone on dotnet247.

'Be nice if this stuff were formally documented...
--

Joseph Geretz



Tue, 01 Feb 2005 23:07:54 GMT  
 POST via HttpWebRequest not working. HELP!
Hi Joseph,

Try System.Net.WebClient() class.

--
Dmitriy Lapshin
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua


Quote:
> Here's how I'm trying to POST a request via HttpWebRequest:

>       If Request.Method = "POST" Then
>          Form = zGetPostForm(ASPPack, Request)
>                                                ' Don't worry about this
>                                                ' returns a byte array
>                                                ' of Form data (X=Y&A=B)
>          If Not Form Is Nothing Then
>             If Form.Length > 0 Then
>                Request.ContentLength = Form.Length
>                zPostForm(Form, Request) ' See method below
>             End If
>          End If
>       End If

>       Response = CType(Request.GetResponse, HttpWebResponse)

>    Private Sub zPostForm(ByRef Form() As Byte, ByRef Request As
> HttpWebRequest)

>       Dim PostBody As System.IO.Stream

>       If Form.Length > 0 Then
>          PostBody = Request.GetRequestStream
>          PostBody.Write(Form, 0, Form.Length)
>          PostBody.Close()
>       End If

>    End Sub

> Here's the HTTP info which comes across to the target ASPX script

> <ALL_HTTP>HTTP_CONTENT_LENGTH:56
> HTTP_COOKIE:FPSNOW=BRAD=Done; VANILLA=Yum;

CHOCOLATE=CHIP1=Yum&CHIP2=YumYum!

- Show quoted text -

Quote:
> HTTP_EXPECT:100-continue
> HTTP_HOST:localhost
> HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;
Q312461;
> .NET CLR 1.0.3705) [BOA.NET]
> </ALL_HTTP>

> So you see the content length came across, as well as a new HTTP_EXPECT,
> which I've never seen before so something's happening. however, the Form
is
> empty! context.Request.Form.Count = 0.

> What am I missing?

> Thanks,
> --

> Joseph Geretz



Tue, 01 Feb 2005 23:11:22 GMT  
 POST via HttpWebRequest not working. HELP!
Joseph,

    It is, it's in the HTTP specification =)

--
               - Nicholas Paldino [.NET/C# MVP]


Quote:
> This was all that was missing

> Request.ContentType = "application/x-www-form-urlencoded"

> Cool! Thanks to Peter Brunone on dotnet247.

> 'Be nice if this stuff were formally documented...
> --

> Joseph Geretz



Tue, 01 Feb 2005 23:15:42 GMT  
 POST via HttpWebRequest not working. HELP!
Hi Nicholas,

Well yes, I guess it is, somewhere.

Silly me. Coming from an HP-3000 background (waaay back when) I actually
expect that the technical specifications for a parameter would actually be
accompanied by a listing, or at least a sample listing of valid values and a
reference to where the complete list can be obtained. Or maybe a definition
of which parameters need to be supplied in concert with one another. Don't
get me wrong. I have a healthy respect for the .NET platform. I've switched
and I'm not interested in going back. But these days it's a lot of 'try
this, try that, then when you get it to work let others know about it.' A
bit of formal documentation would go a long way toward getting people to
adopt.

Hey, maybe I should be in marketing! :-(
--

Joseph Geretz



Quote:
> Joseph,

>     It is, it's in the HTTP specification =)

> --
>                - Nicholas Paldino [.NET/C# MVP]



> > This was all that was missing

> > Request.ContentType = "application/x-www-form-urlencoded"

> > Cool! Thanks to Peter Brunone on dotnet247.

> > 'Be nice if this stuff were formally documented...
> > --

> > Joseph Geretz



Wed, 02 Feb 2005 00:56:24 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Help with posting dropdown values using HttpWebRequest/HttpWebResponse

2. POST method NOT WORKING... pls help

3. Problem Posting data with HttpWebRequest

4. Posting to an ASP page with HttpWebRequest

5. Timing out POST-ing with HttpWebRequest

6. HttpWebRequest and CGI Post

7. Convert form post (httpWebRequest) & Catch response

8. Print Setup via API not working - please help

9. Post to Public Folder not working

10. Large data posts not working??

11. GetChunk with POST, Why does this not work?

12. Inet control does not work with POST method ?

 

 
Powered by phpBB® Forum Software