это какой то кошмар, блин. Проходит первый GET, происходит редирект, на второй GET получается login page. Далее посылается POST, вроде что то шевелится и в ответ приходит ошибка.
Куда копать? Что ковырять? Очень нужен совет!
YES YES YES Всем огромнейшее спасибо. Такой муторной работы я давно не делал. Главное что ведь сломается же все через месяц два когда они изменят свой код. Ну да ладно, надо здесь и сейчас.
Здесь код, может кому пригодится. В комментариях headers из браузера - типа что должно быть:
| Код | import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*;
// requires three jar files // commons-httpclient-3.0.1.jar commons-logging-1.1.jar commons-codec-1.3.jar public class Hidrag {
static HttpClient client = new HttpClient(); static MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
public static void main(String[] args) { readyServer(); }
private static boolean readyServer() { GetMethod getMain = null; HttpState state= new HttpState(); try { client = new HttpClient();
System.out.println("Podgotovka...");
// initial GET /* (Request-Line):GET /gp/seller-account/inventory/list-inventory.html HTTP/1.1 Accept:[deleted niasilil] Accept-Language:en-us UA-CPU:x86 Accept-Encoding:gzip, deflate User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 1.1.4322; .NET CLR 2.0.50727) Host:www.amazon.com Connection:Keep-Alive */ /* response * (Status-Line):HTTP/1.1 302 MovedTemporarily Date:Sun, 27 Apr 2008 02:07:53 GMT Server:Server x-amz-id-1:03C703A1PNXG2FYA3CT0 x-amz-id-2:Mg2jOH3E/H+FfOL22E9n1+4v672HdqHQ Set-cookie:session-id-time=1209798000l; path=/; domain=.amazon.com; expires=Sat May 03 07:00:00 2008 GMT Set-cookie:session-id=104-0559236-2455961; path=/; domain=.amazon.com; expires=Sat May 03 07:00:00 2008 GMT Location:https://www.amazon.com/gp/sign-in.html/104-0559236-2455961?ie=UTF8&email=&disableCorpSignUp=&path=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html&redirectProtocol=&mode=&useRedirectOnSuccess=1&query=%2Aentries%2A%3D0%26%2AVersion%2A%3D1&pageAction=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html Vary:Accept-Encoding,User-Agent Content-Encoding:gzip Content-Type:text/html; charset=ISO-8859-1 Transfer-Encoding:chunked */ /* another request * (Request-Line):GET /gp/sign-in.html/104-0559236-2455961?ie=UTF8&email=&disableCorpSignUp=&path=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html&redirectProtocol=&mode=&useRedirectOnSuccess=1&query=%2Aentries%2A%3D0%26%2AVersion%2A%3D1&pageAction=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html HTTP/1.1 Accept-Language:en-us UA-CPU:x86 Accept-Encoding:gzip, deflate User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 1.1.4322; .NET CLR 2.0.50727) Cookie:session-id-time=1209798000l; session-id=104-0559236-2455961 Connection:Keep-Alive Host:www.amazon.com */ /* response * (Status-Line):HTTP/1.0 200 OK Date:Sun, 27 Apr 2008 02:07:53 GMT Server:Server x-amz-id-1:0M28SZA1ZFQ0YEHKHJ68 x-amz-id-2:IGZioiy3iTTr+CdyCqnZ5b7SMOJx1MoW Set-cookie:ubid-main=002-2169711-2167314; path=/; domain=.amazon.com; expires=Tue Jan 01 08:00:01 2036 GMT Vary:Accept-Encoding,User-Agent Content-Encoding:gzip Content-Type:text/html; charset=ISO-8859-1 Connection:close
*/ client .getParams() .setParameter( "http.useragent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"); client.getParams().setParameter("Accept-Language","en-us"); client.getParams().setParameter("UA-CPU","x86"); client.getParams().setParameter("Accept-Encoding", "gzip, deflate"); client.getParams().setParameter("Host","www.amazon.com"); client.getParams().setParameter("Connection","Keep-Alive");
String url = "http://www.amazon.com/gp/seller-account/inventory/list-inventory.html"; getMain = new GetMethod(url); client.executeMethod(client.getHostConfiguration(), getMain, state);
Header h = getMain.getResponseHeader("Set-Cookie");
getMain.releaseConnection();
String s = h.getValue(); System.out.println(s);
client.getParams().setParameter("Content-Type","application/x-www-form-urlencoded");
/* (Request-Line):POST /gp/flex/sign-in/select.html?ie=UTF8&protocol=https HTTP/1.1 Referer:https://www.amazon.com/gp/sign-in.html/104-0559236-2455961?ie=UTF8&email=&disableCorpSignUp=&path=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html&redirectProtocol=&mode=&useRedirectOnSuccess=1&query=%2Aentries%2A%3D0%26%2AVersion%2A%3D1&pageAction=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html Accept-Language:en-us Content-Type:application/x-www-form-urlencoded UA-CPU:x86 Accept-Encoding:gzip, deflate User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 1.1.4322; .NET CLR 2.0.50727) Host:www.amazon.com Content-Length:834 Connection:Keep-Alive Cache-Control:no-cache Cookie:session-id-time=1209798000l; session-id=104-0559236-2455961; ubid-main=002-2169711-2167314 */ /* (Status-Line):HTTP/1.0 302 MovedTemporarily Date:Sun, 27 Apr 2008 02:08:27 GMT Server:Server x-amz-id-1:05KMAXN74D1Q9TZH71ND x-amz-id-2:IGZioiy3iTTr+CdyCqnZ5b7SMOJx1MoW Set-cookie:x-main=e4HnfmLQDCXbm2zHPecgsdKRFi4dZITu; path=/; domain=.amazon.com; expires=Tue Jan 01 08:00:01 2036 GMT Set-cookie:at-main=2|Xm8cSXc0spffi2r5x9eBpTMEjqM5vbkEqZCNvc1c7tMC2pOA7eCAOz9xKgI0OfDf4KKyNoS+CMsd/xzFb/VjE1/Y4RJAG4b9Rf0w+ItDuZJD07tptR/WI1eS/TyvP28qnOyP0NOcXYeURGp+dnYc5OUgvw7gpKAo2uUW1UMdYLnmu9gw6nn91A==; path=/; domain=.amazon.com; expires=Tue Jan 01 08:00:01 2036 GMT Set-cookie:session-token=9qfS/U5+9zTKa2ztNFSgAjEVxe/KqRWa3TBXsOCSqRJgeryJnGy10CBRgKcKf/gSkjr5th6GB+WQrFcgz84FauV2igFuTsyq3OiUWO1GUsKKDyXRiClYP3DyBHuG86pK1I0/FwGfAIwCxTxn6V5RjD8MEydmtVeGtruUrKJWD0/5milAbL61SRq4qiM+s9HyMQWDFs3o46hE7pDJKURI/kj/wVSQN+BYSCvNOrGP8OeyPWFC9d1A8Fp5XSVvmM2p; path=/; domain=.amazon.com; expires=Sun Apr 27 02:18:27 2008 GMT Location:https://www.amazon.com/gp/seller-account/inventory/list-inventory.html?ie=UTF8&%2AVersion%2A=1&%2Aentries%2A=0 Vary:Accept-Encoding,User-Agent Content-Encoding:gzip Content-Type:text/html; charset=ISO-8859-1 Connection:close */ /* (Request-Line) GET /gp/seller-account/inventory/list-inventory.html?ie=UTF8&%2AVersion%2A=1&%2Aentries%2A=0 HTTP/1.1 Referer https://www.amazon.com/gp/sign-in.html/104-0559236-2455961?ie=UTF8&email=&disableCorpSignUp=&path=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html&redirectProtocol=&mode=&useRedirectOnSuccess=1&query=%2Aentries%2A%3D0%26%2AVersion%2A%3D1&pageAction=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html Accept-Language en-us UA-CPU x86 Accept-Encoding gzip, deflate User-Agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14.52; .NET CLR 1.1.4322; .NET CLR 2.0.50727) Host www.amazon.com Connection Keep-Alive Cache-Control no-cache Cookie session-id-time=1209798000l; session-id=104-0559236-2455961; ubid-main=002-2169711-2167314; x-main=e4HnfmLQDCXbm2zHPecgsdKRFi4dZITu; at-main=2|Xm8cSXc0spffi2r5x9eBpTMEjqM5vbkEqZCNvc1c7tMC2pOA7eCAOz9xKgI0OfDf4KKyNoS+CMsd/xzFb/VjE1/Y4RJAG4b9Rf0w+ItDuZJD07tptR/WI1eS/TyvP28qnOyP0NOcXYeURGp+dnYc5OUgvw7gpKAo2uUW1UMdYLnmu9gw6nn91A==; session-token=9qfS/U5+9zTKa2ztNFSgAjEVxe/KqRWa3TBXsOCSqRJgeryJnGy10CBRgKcKf/gSkjr5th6GB+WQrFcgz84FauV2igFuTsyq3OiUWO1GUsKKDyXRiClYP3DyBHuG86pK1I0/FwGfAIwCxTxn6V5RjD8MEydmtVeGtruUrKJWD0/5milAbL61SRq4qiM+s9HyMQWDFs3o46hE7pDJKURI/kj/wVSQN+BYSCvNOrGP8OeyPWFC9d1A8Fp5XSVvmM2p */ System.out.println("Avtorizatsiya..."); PostMethod postAuth = new PostMethod("https://www.amazon.com/gp/flex/sign-in/select.html?ie=UTF8&protocol=https");
NameValuePair[] data = { new NameValuePair("path", "/gp/seller-account/inventory/list-inventory.html"), new NameValuePair("useRedirectOnSuccess", "1"), new NameValuePair("query", "*entries*=0&*Version*=1"), new NameValuePair("mode", ""), new NameValuePair("redirectProtocol", ""), new NameValuePair("pageAction", "/gp/seller-account/inventory/list-inventory.html"), new NameValuePair("disableCorpSignUp", ""), new NameValuePair("email", "myamazontest@yahoo.com"), new NameValuePair("action", "sign-in"), new NameValuePair("password", "prostoj"), new NameValuePair("metadata1", "IE 7.0-7,0,5730,13 Windows"), new NameValuePair("metadataf1", ""), new NameValuePair("metadata2", "ShockwaveFlash : 393216|AB 6,0,2600,0|WDUN 6,0,2900,2180|DA 6,0,3,531|DAJC 6,0,1,223|DS 11,0,5721,5145|DHDB 7,0,5730,13|DHDBFJ 6,0,1,223|ICW 5,0,2918,1900|IE 7,0,5730,13|WMP 11,0,5721,5145|NN 4,4,0,3400|OBP 7,0,5730,13|OE 6,0,2900,2180|TS 4,71,1968,1|MVM 5,0,5000,0||1680-1050-1020-32-96-96-0"), new NameValuePair("metadata3", "timezone: 5 execution time: 172"), // new NameValuePair("x", "170"), // new NameValuePair("y", "8") }; postAuth.setRequestBody(data);
String cookieId = ""; for(Cookie c: state.getCookies()){ System.out.println(c.toString()); if(c.toString().startsWith("session-id=")){ cookieId = c.toString().substring(11); System.out.println(cookieId); } } client.getParams().setParameter("Referer","https://www.amazon.com/gp/sign-in.html/" + cookieId +"?ie=UTF8&email=&disableCorpSignUp=&path=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html&redirectProtocol=&mode=&useRedirectOnSuccess=1&query=%2Aentries%2A%3D0%26%2AVersion%2A%3D1&pageAction=%2Fgp%2Fseller-account%2Finventory%2Flist-inventory.html"); client.getParams().setParameter("Content-Type","application/x-www-form-urlencoded");
client.executeMethod(client.getHostConfiguration(), postAuth, state);
String redirectLocation; Header locationHeader = postAuth.getResponseHeader("location"); if (locationHeader != null) { redirectLocation = locationHeader.getValue(); System.out.println(redirectLocation); getMain = new GetMethod(redirectLocation); client.executeMethod(client.getHostConfiguration(), getMain, state); } else { // The response is invalid and did not provide the new location for // the resource. Report an error or possibly handle the response // like a 404 Not Found error. }
String body = getMain.getResponseBodyAsString(); System.out.println(body);
getMain.releaseConnection(); postAuth.releaseConnection();
return true;
} catch (Exception e) { e.printStackTrace(); return false; } } }
|
|