473,396 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Making posts to an ASP.NET webform.

hiya everyone,

I've made this little webcrawler using BeautifulSoup, urllib and
urllib2. I've been encountering ASP.NET Forms recently and I can't seem
to make a proper post to some of them. My post function has been doing
great until this particular website.
Here's some explanations first so that you guys understands my
problem...

Usually there are 8 hidden inputs spread all over the web page:
__EVENTTARGET --that is the id of the control that is assigned by the
ASP.NET engine. It is usually in this particular form
"dg_Result$_ctl2$linkbtn1" The javascript function DoPostback usually
replaces the '$' for a ':' before doing the real post. Some other
ASP.NET page doesn't.
__EVENTARGUMENT --nothing's here usually.
__ScrollTop --its value is often 0
__ScrollLeft --same as __ScrollTop
__ValidationSummary --usually empty
__VIEWSTATEENCRYPTED --an encrypted string. I don't know what it
means nor what it does.
__EVENTVALIDATION --an encrypted string. I don't know what it means
nor what it does.
__VIEWSTATE --the encrypted state of the current control. the state
of a datagrid for example.

I extract all those values using regexes on the web page, build a
dictionnary out of all those values and encrypt the whole thing using
urllib.urlencode(). Afterwards I extract the form action and post the
whole thing with cookies enabled. This procedure works like a charm.

The website I've just encounted has only 3 of the 8 hidden inputs.
(EVENTTARGET, EVENTARGUMENT & VIEWSTATE ).
I tried posting the whole thing using only these 3 values & nada.
I then tried posting the whole thing using all empty values for the 5
remaining values...still nothing.

Has anyone tried what I'm doing? and if you tried how have you
succeeded getting the data back after the post action?

thanks for any tips!

cP

Oct 2 '06 #1
5 3712
Bernard skrev:
Has anyone tried what I'm doing? and if you tried how have you
succeeded getting the data back after the post action?
Most likely you get assigned a cookie that you then need to return.

Try the cookielib which automates all this for you.
Oct 2 '06 #2

Max M wrote:
Bernard skrev:
Has anyone tried what I'm doing? and if you tried how have you
succeeded getting the data back after the post action?

Most likely you get assigned a cookie that you then need to return.

Try the cookielib which automates all this for you.
Yea I'm already using it. I set the cookies before making the server
request. its name is ASP.NET_SessionId.

I've tried setting it on & off during my various tests but I still get
the "urllib2.HTTPError: HTTP Error 500: Internal Server Error" message.

thanks for the response by the way :)

Oct 2 '06 #3
At Monday 2/10/2006 13:05, Bernard wrote:
Has anyone tried what I'm doing? and if you tried how have you
succeeded getting the data back after the post action?
Use a packet sniffer or something to look at an actual POST that
works, this way you could see what's missing in your code.
Gabriel Genellina
Softlab SRL

__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Oct 3 '06 #4
Gabriel Genellina wrote:
At Monday 2/10/2006 13:05, Bernard wrote:
Has anyone tried what I'm doing? and if you tried how have you
succeeded getting the data back after the post action?

Use a packet sniffer or something to look at an actual POST that
works, this way you could see what's missing in your code.
Gabriel Genellina
Softlab SRL
Thanks for that suggestion Gabriel. It's really a great idea to see
what's going on behind the scene but it still doesn't work even though
the post made by my function has the same data as a real browser post.

here's the HTTP Header from my sniffer:
-------------------------------------------------------------
http://www.newportrealty.com/Search/...t.aspx?Area=WC

POST /Search/Default.aspx?Area=WC HTTP/1.1
Host: www.newportrealty.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.6)
Gecko/20060728 Firefox/1.5.0.6
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.newportrealty.com/Search/...t.aspx?Area=WC
Cookie: ASPSESSIONIDQQBTTDAT=JMBNNNNBNNJELLBBNCCDMNCK;
ASP.NET_SessionId=hzdjizvca2zid3f205s5kd45
Content-Type: application/x-www-form-urlencoded
Content-Length: 4649
__EVENTTARGET=dg_Result%3A_ctl1%3A_ctl1&__EVENTARG UMENT=&__VIEWSTATE=dDw0MD(...)
HTTP/1.x 200 OK
Cache-Control: private
Content-Length: 37519
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Date: Wed, 04 Oct 2006 15:15:37 GMT
-------------------------------------------------------------

and here's the output of the encoded data as well as the cookies in my
function:

-------------------------------------------------------------
cookies:
<Cookie ASP.NET_SessionId=lddb3iruopvpnjiar0dlytvi for
www.newportrealty.com/>
<Cookie ASPSESSIONIDQQBTTDAT=OMBNNNNBMLDDAIHNDHJGLFKP for
www.newportrealty.com/>

encoded post data:
__EVENTTARGET=dg_Result%3A_ctl14%3A_ctl2&__EVENTAR GUMENT=&__VIEWSTATE=dDw0MDAyOTcw(...)
-------------------------------------------------------------

My function has already worked on other asp.net websites and I'm pretty
sure this would work out just fine. is there something I'm missing here?

Oct 4 '06 #5

Bernard wrote:
Gabriel Genellina wrote:
At Monday 2/10/2006 13:05, Bernard wrote:
Has anyone tried what I'm doing? and if you tried how have you
succeeded getting the data back after the post action?
Use a packet sniffer or something to look at an actual POST that
works, this way you could see what's missing in your code.
Gabriel Genellina
Softlab SRL

Thanks for that suggestion Gabriel. It's really a great idea to see
what's going on behind the scene but it still doesn't work even though
the post made by my function has the same data as a real browser post.

here's the HTTP Header from my sniffer:
-------------------------------------------------------------
http://www.newportrealty.com/Search/...t.aspx?Area=WC

POST /Search/Default.aspx?Area=WC HTTP/1.1
Host: www.newportrealty.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.6)
Gecko/20060728 Firefox/1.5.0.6
Accept:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.newportrealty.com/Search/...t.aspx?Area=WC
Cookie: ASPSESSIONIDQQBTTDAT=JMBNNNNBNNJELLBBNCCDMNCK;
ASP.NET_SessionId=hzdjizvca2zid3f205s5kd45
Content-Type: application/x-www-form-urlencoded
Content-Length: 4649
__EVENTTARGET=dg_Result%3A_ctl1%3A_ctl1&__EVENTARG UMENT=&__VIEWSTATE=dDw0MD(...)
HTTP/1.x 200 OK
Cache-Control: private
Content-Length: 37519
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Date: Wed, 04 Oct 2006 15:15:37 GMT
-------------------------------------------------------------

and here's the output of the encoded data as well as the cookies in my
function:

-------------------------------------------------------------
cookies:
<Cookie ASP.NET_SessionId=lddb3iruopvpnjiar0dlytvi for
www.newportrealty.com/>
<Cookie ASPSESSIONIDQQBTTDAT=OMBNNNNBMLDDAIHNDHJGLFKP for
www.newportrealty.com/>

encoded post data:
__EVENTTARGET=dg_Result%3A_ctl14%3A_ctl2&__EVENTAR GUMENT=&__VIEWSTATE=dDw0MDAyOTcw(...)
-------------------------------------------------------------

My function has already worked on other asp.net websites and I'm pretty
sure this would work out just fine. is there something I'm missing here?

ok my bad I've just found out that I didn't build properly the form
action url!! It works now!

thanks for all the responses!!

Oct 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew | last post by:
Hi, Until now, I have used a single webform for my web app, and everything's been OK. Now, I've decided to create a main menu webform. So, I've got two webforms. Using Visual Studio .NET (with...
1
by: hqdtech | last post by:
how to refresh webform from other webform I have 2 webform, i want if webform A was close then webform B wil refresh. And the problem second: how to catch packet on the network in C#. ...
3
by: trint | last post by:
Ok, I have tried to do this with the System.Web.UI and can't find anything for the webform. It seems much easier for a Winform. Any help in trapping Webform keydown event and keyup event is...
5
by: Jerry | last post by:
I am using .Net 2003. I have been working with this ASP.Net webform that I created a few weeks ago. It has been working fine. However, while modifying the webform today, this webform stopped...
1
by: Tammy | last post by:
Hi I am working on a portal that will serve up reporting services reports. The user will have a basic home page and from there will be able to run their reports. As each report is run, I need to...
2
by: Craig Douthitt via DotNetMonster.com | last post by:
I am trying to capture an buttonclick on a usercontrol in the webform the usercontrol resides in. After researching this issue, I've come to believe that the best way of handling this is by raising...
14
by: Mike C# | last post by:
Hi all, Is it possible to make 10 POST requests from ASP.NET asynchronously? I have been working on this problem for a few days now, and I seem to keep running up against IIS limitations. ...
0
by: =?Utf-8?B?TWljaGFlbCBkZSBWZXJh?= | last post by:
To all, I'm trying to use ajax in my web site project but everytime I hit the button on my webform the whole page posts back. The label control that I have in my update panel does what it is...
5
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have start web form and when the user clicks a button (server.transfer) they are directed to the second webform. I was wondering if there is a way to create an instance of the first webform...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.