simulating postback to webform

  • Thread starter Thread starter James Bush
  • Start date Start date
J

James Bush

Hi there,

Can anyone help me Im going insane here!!!

Ive built an atl composite control for pocket pc using embedded VC++
3. THe control is intended to simulate a postback to an asp.net web
form to post a file from pocket pc to the web server. pocket ie does
not support the input type=file html tag to im having to do it
manually.

So ive got an activex control working fine, im adding exectly the same
headers as IE5.5 etc... would add to the post, the post is being sent
to the web server no probs (using wininet functions). Ive verified
that the content is reaching the server intact (_rawcontent is
correct). But asp.net does not recognise the post as a postback and
does not fire the required events etc...

Ive simulated a postback from the clientside javascript function
dopostback; i.e. ive got post form fields called __EVENTTARGET and
__EVENTARGUMENT etc... Im pretty sure my content is formed OK.

However, asp.net does not recognise the request as a postback!!!
ARGGHH!! Ive tried copying the __VIEWSTATE field into the post data as
well but no difference!!

Please help! How does asp.net recognise an incoming http post as a
postback!?

Many thanks,
James.
(UK)
 
also forgot to mention that asp.net does not seem to recognise the multipart
sections of the form at all. Im pretty sure my content-length is correct
etc... im loosing hair very quickly!!
 
for .net to recognise a postback it looks in the __Viewstate hidden field.
your app needs to do a GET of the the upload page to get a valid viewstate
to POST back.

if .net does not see your file, then you are probably not correctly building
the mime multi-part content.

a simple text upload should look something like:


Content-Type: multipart/form-data;
boundary=---------------------------7d4b4f4502aa


-----------------------------7d4b4f4502aa
Content-Disposition: form-data; name="__EVENTTARGET"

Button1
-----------------------------7d4b4f4502aa
Content-Disposition: form-data; name="__EVENTARGUMENT"


-----------------------------7d4b4f4502aa
Content-Disposition: form-data; name="__VIEWSTATE"

dDwtNjQzNzE0OTg3Ozs+C6R48Civas5gJJq3DkYDB4iyOBI=
-----------------------------7d4b4f4502aa
Content-Disposition: form-data; name="File1"; filename="C:\test.txt"
Content-Type: application/octet-stream

this is a test file

-----------------------------7d4b4f4502aa


-- bruce (sqlwork.com)
 
Hi there Bruce,

Many thanks for your reply. Im a 'sole developer' and Im really in one of
those bad places at the moment!! ;-)

I am doing pretty much what you suggest with __VIEWSTATE...just to see if I
can get the thing working I have a 'special' proxy server that lets me
'sniff' http headers to and from the server. I have duplicated as closely as
possible the POST format that IE6 sends to the server when doing a normal
file upload (with the input type=file tag). Viewstate does not appear to
change between requests (unless the page changes - which it doesnt in my
case...at least I dont think it does....better check that!!) so I just pass
it to my control using a PARAM argument in the html.

Im really stumped! Im getting to the stage where Im tweaking, recompiling
and testing every 30 seconds just to get some sort of different response to
point me in the right direction.

I notice in your post you have a crlf between the end of your text file and
the closing seperator. Was this intentional? i.e. is it required? Also, I
notice that the closing seperator is identical to the others; I have noticed
that sometimes there are additional characters beyond the end like -- for
instance. Is this for a particular reason do you know?

Once again, thanks for giving me some hope!! :-)

James.



bruce barker said:
for .net to recognise a postback it looks in the __Viewstate hidden field.
your app needs to do a GET of the the upload page to get a valid viewstate
to POST back.

if .net does not see your file, then you are probably not correctly building
the mime multi-part content.

a simple text upload should look something like:


Content-Type: multipart/form-data;
boundary=---------------------------7d4b4f4502aa


-----------------------------7d4b4f4502aa
Content-Disposition: form-data; name="__EVENTTARGET"

Button1
-----------------------------7d4b4f4502aa
Content-Disposition: form-data; name="__EVENTARGUMENT"


-----------------------------7d4b4f4502aa
Content-Disposition: form-data; name="__VIEWSTATE"

dDwtNjQzNzE0OTg3Ozs+C6R48Civas5gJJq3DkYDB4iyOBI=
-----------------------------7d4b4f4502aa
Content-Disposition: form-data; name="File1"; filename="C:\test.txt"
Content-Type: application/octet-stream

this is a test file

-----------------------------7d4b4f4502aa


-- bruce (sqlwork.com)
<snip>
 
Just thought Id post the solution to this problem in case anyone searches
this group in future...

This has been a real headache so I hope it may save someone else the
trouble!!

Content boundaries must be prefixed with an additional 'dash-dash' in the
actual post body i.e.

--

the boundary you specify in the header must not contain these leading two
dash (minus symbol) characters. I was supplying the same boundary in the
header that I was using as the actual seperator. It is noted in the post
specification that this is the case. I guess I should have read the
manual.....DOH!!! ;-)

eg.

Content-Type=multipart/form-data; boundary=abcdefg

etc.....

then in your body use

--abcdefg

as the seperator line.

James.

keywords: http post form boundry webform postback simulate wininet asp.net
 
Back
Top