开发者

How to fabricate ASPX POST request

I'm battling with this for days, I have an ASPX page that has a file upload control and an upload button, and no matter what I do, I can't get the page to accept the autom开发者_如何学Cated POST request.

The request body is as follows (all newlines CRLF), all UTF8 == ANSII (no spec chars right now)

-----------------------------8cdc74445fc88d0
Content-Disposition: form-data; name="btnUpload"

Upload
-----------------------------8cdc74445fc88d0
Content-Disposition: form-data; name="ctrFileUpload"; filename="myfile.txt"
Content-Type: text/plain

This is a test!

-----------------------------8cdc74445fc88d0--

The form has multiple buttons, so I need to kinda fill the file upload, and press the upload button. But this doesn't seem to work.

The same page works just fine from a web browser, although, in that scenario there is a viewstate garbage as one of the parts. I tried EnableViewState="false", ValidateRequest="false", EnableSessionState="ReadOnly", but the garbage part is still there when I use the browser.

Am I missing something? Tried studying the RFC and everything, but nothing seems to work.


Why not use fiddler to compare your post with the post that works..


POST request is post request - it is same for browser and other applications. All you need to accomplish post is set http verb (method) when creating request. If you use .net as request generator from your application, this can be done by setting HttpWebRequest.Method Property. There're also examples there

Aaaaargh, everything is clear now. There're no 'events' in http. Asp.net webforms introduced this(and many others) approach to make developing on web easier as i believe for those who had found difficult to program on web because of http statelessness or were bound to windows development. Asp.net webforms make web development much more like windows development. As i mentioned - there're no events in http protocol. So, asp.net uses viewstate garbage and its dopostbackwithoptions function to bind http client side clicks to server side events. That's why your automated post does not work - when that viewstate garbage is missing, webforms engine has no chance to bind to events. You should handle web request otherwise - without relying on events


You don't actually need the viewstate for a form to work, unless there is something in there that is needed. what you do need is to make sure the name of button that is clicked to submit the form is included in your submitted data.

The clicked control is needed so that asp.net can figure out on which control to raise the click event. the viewstate is just a list of key:value pairs for each control that are different to the default values. by comparing these values to the submitted values it can raise onchange events etc.


I also don'T know what an "automated post request" is, but setting

<form ... enctype="multipart/form-data">

on your form tag might help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜