问题描述
stringhtml="";HttpWebResponseresponse=null;this.RequestUri=newUri(url);HttpWebRequestrequest=WebRequest.Create(this.RequestUri)asHttpWebRequest;try{if(url.StartsWith("https",StringComparison.OrdinalIgnoreCase)){ServicePointManager.ServerCertificateValidationCallback=newRemoteCertificateValidationCallback(CheckValidationResult);request=WebRequest.Create(url)asHttpWebRequest;}else{request=WebRequest.Create(url)asHttpWebRequest;}request.Method="POST";request.UserAgent="Mozilla/5.0(WindowsNT6.1;WOW64;rv:36.0)Gecko/20100101Firefox/36.0";request.Host="www.amazon.com";request.Accept="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";request.KeepAlive=true;request.Headers["Accept-Language"]="zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3";request.ContentType="application/x-www-form-urlencoded";request.Headers["Accept-Language"]="gzip,deflate";request.Referer="https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26action%3Dsign-out%26path%3D%252Fgp%252Fyourstore%252Fhome%26ref_%3Dnav_youraccount_signout%26signIn%3D1%26useRedirectOnSuccess%3D1";stringpostData="appActionToken=6j2Bf3fAi9L1j0dnAP1oI58HktaxUj3D&appAction=SIGNIN&openid.pape.max_auth_age=ape%3AMA%3D%3D&openid.ns=ape%3AaHR0cDovL3NwZWNzLm9wZW5pZC5uZXQvYXV0aC8yLjA%3D&openid.ns.pape=ape%3AaHR0cDovL3NwZWNzLm9wZW5pZC5uZXQvZXh0ZW5zaW9ucy9wYXBlLzEuMA%3D%3D&prevRID=ape%3AMEdQNzBSMk1ZRThWRkUxN1ZXWjc%3D&pageId=ape%3AdXNmbGV4&openid.identity=ape%3AaHR0cDovL3NwZWNzLm9wZW5pZC5uZXQvYXV0aC8yLjAvaWRlbnRpZmllcl9zZWxlY3Q%3D&openid.claimed_id=ape%3AaHR0cDovL3NwZWNzLm9wZW5pZC5uZXQvYXV0aC8yLjAvaWRlbnRpZmllcl9zZWxlY3Q%3D&openid.mode=ape%3AY2hlY2tpZF9zZXR1cA%3D%3D&openid.assoc_handle=ape%3AdXNmbGV4&openid.return_to=ape%3AaHR0cHM6Ly93d3cuYW1hem9uLmNvbS9ncC95b3Vyc3RvcmUvaG9tZT9pZT1VVEY4JnJlZl89bmF2X3lhX3NpZ25pbg%3D%3D&email=yhyinhu@163.com&create=0&password=yh91011023&metadata1=EPdH9iurGItrD1w6AJhpX9gIJdbrc0qynuTiUDlDELuX4HcwRYsi%2BQwXOIrEONQdfE9ByIMdf84wqIP3Oh%2FPKUMQKFSTf0%2FqYHm1xB4JHWOAh%2B%2Fm%2FTvG52yi6yDgld2R6oymdegOosADGruRsHR7MMAWEaakUVRZDjA8wctbIMUZU6tKTQCqgWHxo9AH%2F3d6u3Tz86Wi5hY6T4v1X2cR7xpJqLCPbaIGhDBDcKFlOEBP0Nm8DVxb2zUM%2FK7XWc%2Fx5yLJMaXztRSQcJRrm3yOzW0B%2By5TgnJljadRNOmnktwBjQhwduDCB%2BisGHVr1E8A3BXNb3gPFamVOtJAEgEt8jhpYiZMCKOmEPU3sKNXfSvkG3LUrjmKZP01UzbQq1zA6uyBCs9MyQ6y8VJwhE8ae2orM%2BbYIDGF%2FXkZfDqp%2Fo9z2w%2FdrE4x%2BVn0RYbGPIJLn%2FRrXCMKiz07OrvpnAay4djcPAx31vZaT2g6nrciecgXFxQadIwAyfGulaZP50PtwhAFkr76XVZB3DhZyv%2ByBDioHiFxiMJ8E3ceABary1drPIehK8QsPISLJ0cDSHvgdJnixlHRxQEUrgpl4a3PPxszgPhgdqgjDwiJ737Ah74TusKL%2B56mc%2Bra6WroBJ9sBuT2BbnOi8fLX0SniggLZRmR2X40xWA8WWvDQrTnnZC1K1s1mxBSRSSyATy%2FoBJoRS%2FqGfxy%2FTZUUWWF4A0D7IWX3Yu16TwhObRn4wVRbLdVi3d%2BWDlydCE1k%2BqGK%2FXZ01aQ1Jdhtu5aPZx%2B0lqcVzMOPEkcbAuZM49mmK695KFt55vlu%2FLs7mM3mQJ6sWdJtYWA7LhhScK84mUaJjC6aA2f7JoUCGAFzF52x6CtE%2F3cMMKY0CGXdu00SRGpCT2vnEaBDeJ6%2Fms4ihiRCPA36odmgu4BvbhnOqXler55RUggEY58nD9OtCGlTvdB7Gk6Vji4Xmgc8wA%3D";EncodingmyEncoding=Encoding.UTF8;//myEncoding=Encoding.Unicode;//myEncoding=Encoding.ASCII;//myEncoding=Encoding.Default;byte[]byteArray=myEncoding.GetBytes(strPostData.ToString().TrimEnd('&'));byte[]buffer=myEncoding.GetBytes(postData);intaa=buffer.Length;request.ContentLength=buffer.Length;request.GetRequestStream().Write(buffer,0,buffer.Length);HttpWebResponsewresp=(HttpWebResponse)request.GetResponse();response=(HttpWebResponse)request.GetResponse();stringstrHtml="";stringcharset=response.CharacterSet;Encodingee=Encoding.UTF8;try{if(charset.Length>0&&!charset.Contains("ISO"))ee=Encoding.GetEncoding(charset);}catch{ee=Encoding.Default;}if(response.ContentEncoding.ToLower().Contains("gzip")){using(GZipStreamstream=newGZipStream(response.GetResponseStream(),CompressionMode.Decompress)){using(StreamReaderreader=newStreamReader(stream,ee)){strHtml=reader.ReadToEnd();}}}elseif(response.ContentEncoding.ToLower().Contains("deflate")){using(DeflateStreamstream=newDeflateStream(response.GetResponseStream(),CompressionMode.Decompress)){using(StreamReaderreader=newStreamReader(stream,ee)){strHtml=reader.ReadToEnd();}}}else{using(Streamstream=response.GetResponseStream()){using(StreamReaderreader=newStreamReader(stream,ee)){strHtml=reader.ReadToEnd();}}}returnstrHtml;}catch(Exceptionhe){stringh=he.Message;return"";}以上postdata参数是使用httpwatch获得的,为什么返回标识符是200(OK),取得的html代码是登录页面,是因为每次重新登录以后的参数都要重新读取么?而且返回的header头中没有local重定向,应该是登录不成功的
解决方案
解决方案二:
跟我遇到的问题一样啊貌似现在灌水的人多了技术的就少了http://bbs.csdn.net/topics/391000335
解决方案三:
参数应该是动态的,不能直接写在代码里面吧
解决方案四:
cookie没传