Vous êtes sur la page 1sur 4

VaibhavBora

YourMindIsYourOwnLimitation
HOME
ABOUT
CONTACT
MyFirstBlogCURLClasswithcookiesupport
UsingCURLforASPXwithVIEWSTATE
OnAugust29,2009,inPHP,byVaibhav
LastnightIwastryingtousecurlfordatamininginPHP.ThewebsitewasbuiltinASPXandusedSession.Asweallknow
ASP.nethasserversidecontrolswhosestateisstoredinthehidden__VIEWSTATEvariableintheform,Ihadtosendthis
VIEWSTATEvariableasmypostvariabletogetthedesiredresponse.
AftertryingforafewhourswithnosuccessIwaswonderingwhatwaswrong.AftersomeresearchIcameacrosssomearticle
thatsuggestedusingLiveHttpHeadersplugininFirefoxtoviewwhatexactrequestisbeingsent.Thenafterlookingatthe
RequestHeaderIfoundthattheVIEWSTATEneedstobeURLencoded!!andthereIgotmydesiredresponseinstantly.
ToconcludeifwesendPOSTparameterswithCURLmakesureyouencodethemandsendintheproperorder.
CheckoutmyotherpostCURLClassthatwillhelpyouwritecodetosendrequeststopagesthatneedcookies.
AlsocheckoutConvertHTMLtowellformedXMLdocument(CleanHTML)withSgmlReaderorphp_tidyposttogetinsighton
howtoextractinformationfromHTML.

9ResponsestoUsingCURLforASPXwithVIEWSTATE
Justinsays:
September15,2009at7:57am
IhadasimilarproblemwhenusingCURLbutImonestepbehind.HowdoyoucapturetheinitialVIEWSTATEand
EVENTVALIDATIONfieldstourlencodebackinthePOSTresponse?
Reply
Vaibhavsays:
September15,2009at11:05am
InmysenarioIusedhardcodedVIEWSTATEvariableforthefirstrequestandthenIreadtheVIEWSTATEvaluefromthe
response.
IfyoudontknowtheVIEWSTATEvalueoritisdynamictheninthissenarioyousimplysendtheGETrequestwithout
VIEWSTATE.YouwillgettheVIEWSTATEintheresponseandallotherparameters.Youcanusephp_tidyextensionto
parse+cleanthehtmlandusexquerytofetchtherequiredvariables.Hopethathelps.
Reply
Opalasays:
March16,2010at4:21pm

Vaibhav,
CouldyoutellmetheexactversionofcURL/phpyouuse.IstartedtoexperienceaproblemwithmyscriptonceIupgradedmy
OS,soIsupposedthatsanissuewithcURLsPOSTand302redirectafterthat.Also,couldyoupastemesomepartofyour
code.Thanks!
Reply
Trikkssays:
June2,2010at12:16pm
Hi!
IminterestedinthesameasOpala.Abriefofthecodewouldbenice!
Reply
fidesays:
January18,2011at2:28am
Hello,
thanksforyourhints,Ihaveexactlythesameproblem.Acodeexamplewouldbeveryappreciated.Thankyou
Reply
DavidStewartsays:
February17,2011at3:41pm
Iwouldlovetoseeademoofyoucode.Haveyousomeexamplesofhowyouhavedonetheencodeon_viewstateandothers?
Thanks.
Reply
Mikesays:
February28,2012at11:23am
Iranintoanerror:ValidationofviewstateMACfailed.Basically,aninvalidviewstate,althoughihaverawurlencodedall
data.
Haveyourunintothis??
Reply
Vaibhavsays:
February28,2012at1:39pm
IhaveseenthiserrorusuallywhenthewebsiteisservedfromaWebFarm(multipleIISServer).Itdoesntrecognizethe
ViewStatebecauseofincorrectkeysconfiguredontheserver.Youhavetomakesureyousendallparameters:__VIEWSTATE,
__EVENTTARGET,__EVENTARGUMENT.
Reply
Mikesays:
February29,2012at12:25am

Yes,Iseewhatyouresayingnow,andImsendingthevalue(s)sentbytheir__doPostBackjsfunction,buttheresultisthe
same.
MaybetheresjustsomethingImdoingwrong,IlltryusingyourCURLclasstohelpclearoutanythingImightbedoing
incorrectly.
Thanks
Reply
LeaveaReply
Name(required)
Mail(willnotbepublished)(required)
Website

CATEGORIES
.NET(2)
Career(1)
CloudComputing(1)
Education(7)
Entrepreneurship(2)
General(2)
PHP(3)
TechnicalArticles(2)
TAGS
ARTICLES
October2009
September2009
August2009
October2008
LINKS
ExxatSystems
META
Login

Entries(RSS)
GOTOTOP
VaibhavBora
Pages
Home
About
Contact
StayInTouch
SiteRSSFeed
More

Vous aimerez peut-être aussi