使用httpwebrequest登录

时间:2012-08-08 02:29:25

标签: httpwebrequest

我正在尝试通过httpwebrequest登录此网站https://www.bewickedcostumes.com/login.php

//这是GET

https://www.bewickedcostumes.com/login.php?open_in_layer=Y&is_ajax_request=Y&keep_https=Y

GET /login.php?open_in_layer=Y&is_ajax_request=Y&keep_https=Y HTTP/1.1
Host: www.bewickedcostumes.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Referer: https://www.bewickedcostumes.com/login.php
Cookie: store_language=en; __atuvc=22%7C31%2C14%7C32; RefererCookie=http%3A%2F%2Fwww.bewickedcostumes.com%2Fproduct.php%3Fproductid%3D18078%26cat%3D%26bestseller%3DY; GreetingCookie=Sammy+Chan; xid_d9db5C_remember=schan%40dropshipinc.com; xid_d9db5=21e18e3615c5ed2ef0597789bcd74746
If-Modified-Since: Wed, 08 Aug 2012 01:49:39 GMT

HTTP/1.1 200 OK
Date: Wed, 08 Aug 2012 02:10:57 GMT
Server: Apache
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: private, must-revalidate
P3P: CP="NON CURa ADMa DEVa TAIa CONi OUR DELa BUS IND PHY ONL UNI PUR COM NAV DEM STA"
Set-Cookie: xid_d9db5=21e18e3615c5ed2ef0597789bcd74746; path=/; domain=www.bewickedcostumes.com; httponly
Last-Modified: Wed, 08 Aug 2012 02:10:57 GMT
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 1220
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1


//这是POST

https://www.bewickedcostumes.com/login.php?open_in_layer=Y&is_ajax_request=Y&keep_https=Y

POST /login.php?open_in_layer=Y&is_ajax_request=Y&keep_https=Y HTTP/1.1
Host: www.bewickedcostumes.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: https://www.bewickedcostumes.com/login.php
Content-Length: 119
Cookie: store_language=en; __atuvc=22%7C31%2C14%7C32; RefererCookie=http%3A%2F%2Fwww.bewickedcostumes.com%2Fproduct.php%3Fproductid%3D18078%26cat%3D%26bestseller%3DY; GreetingCookie=Sammy+Chan; xid_d9db5C_remember=schan%40dropshipinc.com; xid_d9db5=21e18e3615c5ed2ef0597789bcd74746
Pragma: no-cache
Cache-Control: no-cache
xid_d9db5=21e18e3615c5ed2ef0597789bcd74746&is_remember=&mode=login&username=schan%40dropshipinc.com&password=4700Miller

HTTP/1.1 200 OK
Date: Wed, 08 Aug 2012 02:11:06 GMT
Server: Apache
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: private, must-revalidate
P3P: CP="NON CURa ADMa DEVa TAIa CONi OUR DELa BUS IND PHY ONL UNI PUR COM NAV DEM STA"
Set-Cookie: xid_d9db5=21e7b58ed5b06ad7d5897ad641186f8b; path=/; domain=www.bewickedcostumes.com; httponly
Set-Cookie: GreetingCookie=Sammy+Chan; expires=Mon, 04-Feb-2013 02:11:06 GMT; path=/; domain=www.bewickedcostumes.com; httponly
Last-Modified: Wed, 08 Aug 2012 02:11:06 GMT
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Content-Length: 193
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

我的代码可以登录很多网站但是使用这个网站它不起作用。

1 个答案:

答案 0 :(得分:0)

此部分是一个唯一的代码,它在“登录”页面上通过它的外观生成: xid_d9db5 = 21e18e3615c5ed2ef0597789bcd74746

刮掉上述字段&价值与价值将其添加到POST请求中,而不是将上面的确切代码添加到您的请求中。

(您可能还想稍微隐藏您的POST数据,以免在其他地方使用它们的详细信息!)