简体   繁体   English

如何制作ASPX POST请求

[英]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 automated POST request. 我已经为此奋斗了几天,我有一个ASPX页面,该页面具有文件上传控件和一个上传按钮,无论我做什么,我都无法使该页面接受自动POST请求。

The request body is as follows (all newlines CRLF), all UTF8 == ANSII (no spec chars right now) 请求正文如下(所有换行符都是CRLF),所有UTF8 == ANSII(现在没有规范字符)

-----------------------------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. 从Web浏览器可以正常使用同一页面,尽管在这种情况下,viewstate垃圾是其中的一部分。 I tried EnableViewState="false", ValidateRequest="false", EnableSessionState="ReadOnly", but the garbage part is still there when I use the browser. 我尝试了EnableViewState =“ false”,ValidateRequest =“ false”,EnableSessionState =“ ReadOnly”,但使用浏览器时,垃圾部分仍然存在。

Am I missing something? 我想念什么吗? Tried studying the RFC and everything, but nothing seems to work. 试图研究RFC和所有内容,但似乎无济于事。

为什么不使用Fiddler将您的帖子与有效的帖子进行比较。

POST request is post request - it is same for browser and other applications. POST请求是发布请求-浏览器和其他应用程序相同。 All you need to accomplish post is set http verb (method) when creating request. 创建请求时,只需完成设置HTTP动词(方法)即可完成发布。 If you use .net as request generator from your application, this can be done by setting HttpWebRequest.Method Property . 如果使用.net作为应用程序的请求生成器,则可以通过设置HttpWebRequest.Method Property来完成。 There're also examples there 那里也有例子

Aaaaargh, everything is clear now. Aaaaargh,一切现在都清楚了。 There're no 'events' in http. 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引入了此方法(以及许多其他方法),以使在Web上开发变得更容易,因为我相信对于那些由于http无状态而难以在Web上编程或受Windows开发束缚的人。 Asp.net webforms make web development much more like windows development. Asp.net Web表单使Web开发更像Windows开发。 As i mentioned - there're no events in http protocol. 正如我提到的-http协议中没有事件。 So, asp.net uses viewstate garbage and its dopostbackwithoptions function to bind http client side clicks to server side events. 因此,asp.net使用viewstate垃圾及其dopostbackwithoptions函数将http客户端点击绑定到服务器端事件。 That's why your automated post does not work - when that viewstate garbage is missing, webforms engine has no chance to bind to events. 这就是为什么您的自动发布不起作用的原因-当缺少viewstate垃圾时,webforms引擎将没有机会绑定到事件。 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. 需要单击控件,以便asp.net可以找出在哪个控件上引发click事件。 the viewstate is just a list of key:value pairs for each control that are different to the default values. viewstate只是每个控件的key:value对的列表,这些对不同于默认值。 by comparing these values to the submitted values it can raise onchange events etc. 通过将这些值与提交的值进行比较,可以引发onchange事件等。

I also don'T know what an "automated post request" is, but setting 我也不知道什么是“自动发布请求”,但是设置

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

on your form tag might help. 在表单标签上可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM