Advertisement
Guest User

Untitled

a guest
Dec 4th, 2013
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. executing request:GET https://www.dropbox.com/login HTTP/1.1
  2. ----------------------------------------
  3. HTTP/1.1 200 OK
  4. Request Token: moiejtzdLqTA_0sh3gQyNZAI
  5.  
  6. executing request:POST https://www.dropbox.com/login HTTP/1.1
  7. ----------------------------------------
  8. HTTP/1.1 200 OK
  9. Access Token: 5Ot52QKDbDPSsL1ApU4MIapJ
  10.  
  11. executing request:POST https://dl-web.dropbox.com/upload?
  12.  
  13. name=sample.jpg&dest=upload&cookie_t=5Ot52QKDbDP....SsJ&t=5Ot5...apJ HTTP/1.1
  14. ----------------------------------------
  15. HTTP/1.1 400 Bad Request
  16.  
  17. https://dl-web.dropbox.com/chunked_upload?
  18. name=tmp1.jpg
  19. &chunk=0
  20. &chunks=1
  21. &bjar=W3sic2Vzc1..............Q%253D%253D
  22. &blid=AAAw4tn................2cDxA
  23. &cookie_t=32yq........nw6c34o
  24. &dest=
  25. &t=32yqVof........c34o
  26. &reported_total_size=5611
  27. &upload_id=1BKGRRP5TpCEjcWSu5tmpQ
  28. &offset=0
  29.  
  30. https://dl-web.dropbox.com/chunked_upload?
  31. name=tmp1.jpg
  32. &chunk=0
  33. &chunks=1
  34. &bjar=W3sic2Vzc1..............Q%253D%253D
  35. &blid=AAAw4tn................2cDxA
  36. &cookie_t=32yq........nw6c34o
  37. &dest=
  38. &t=32yqVof........c34o
  39. &reported_total_size=5611
  40. &upload_id=1BKGRRP5TpCEjcWSu5tmpQ
  41. &offset=0
  42.  
  43. // constructor ...
  44. public HttpClientExample() {
  45. gcookies = new BasicCookieStore();
  46. globalConfig = RequestConfig.custom()
  47. .setCookieSpec(CookieSpecs.BEST_MATCH)
  48. .build();
  49.  
  50. // Create local HTTP context
  51. ghttpContext = HttpClientContext.create();
  52. ghttpContext.setCookieStore(gcookies);
  53.  
  54. //
  55. redirectStrategy = new LaxRedirectStrategy(); // for http redirect ...
  56. httpclient = HttpClients.custom()
  57. .setDefaultRequestConfig(this.globalConfig)
  58. .setDefaultCookieStore(this.gcookies)
  59. .setRedirectStrategy(redirectStrategy)
  60. .build();
  61. } // constructor ...
  62.  
  63. public static void main(String[] args) throws Exception {
  64.  
  65. HttpClientExample myhttp = new HttpClientExample();
  66. try {
  67.  
  68. this.localConfig = RequestConfig.copy(this.globalConfig)
  69. .setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY)
  70. .build();
  71.  
  72. String requestToken = this.getRequestToken(httpclient, loginurl);
  73.  
  74. theAccessToken = this.postForAccessToken(requestToken, loginurl);
  75.  
  76. String localFileTopassIn = this.localPath ;
  77. this.postToUpload(httpclient, this.theAccessToken, localFileTopassIn , this.dropboxFolderOnlyName);
  78.  
  79.  
  80. }
  81.  
  82. }
  83.  
  84. private String getRequestToken(HttpClient client, String theURL) throws Exception {
  85. HttpGet httpget = new HttpGet(theURL);
  86. httpget.setConfig(localConfig);
  87. httpget.setHeader("Connection", "keep-alive");
  88.  
  89. System.out.println("nexecuting request:" + httpget.getRequestLine());
  90.  
  91.  
  92. // Create a custom response handler
  93. ResponseHandler responseHandler = new ResponseHandler() {
  94.  
  95. public String handleResponse(final HttpResponse response)
  96. throws ClientProtocolException, IOException {
  97. int status = response.getStatusLine().getStatusCode();
  98. if (status >= 200 ) { // && status cookies = gcookies.getCookies();
  99. for (Cookie aCookie: cookies) {
  100. String cookieName = aCookie.getName();
  101. if ( !(cookieName.lastIndexOf(gvcString) == -1) ) {
  102. gvc = aCookie.getValue();
  103. } else if ( !(cookieName.lastIndexOf(tString) == -1) ) {
  104. requestToken = aCookie.getValue();
  105. }
  106. }
  107.  
  108. System.out.println("Request Token: " + requestToken );
  109. return requestToken;
  110.  
  111. }
  112.  
  113. private String postForAccessToken(HttpClient client, String requestToken, String theURL) throws Exception{
  114. /*
  115. * Send a post together with request token and my login to get accessToken ...
  116. */
  117. HttpPost httppost = new HttpPost(theURL); // loginurl);
  118. httppost.setConfig(localConfig);
  119. ghttpContext.setCookieStore(gcookies);
  120.  
  121. List params = new LinkedList();
  122. params.add(new BasicNameValuePair("login_email", myemail));
  123. params.add(new BasicNameValuePair("login_password", mypasswd));
  124. params.add(new BasicNameValuePair("t", requestToken));
  125.  
  126. HttpEntity postentity = new UrlEncodedFormEntity(params);
  127. httppost.setEntity(postentity);
  128.  
  129. System.out.println("nexecuting request:" + httppost.getRequestLine());
  130.  
  131. // Create a custom response handler
  132. ResponseHandler responseHandler = new ResponseHandler() {
  133.  
  134. public String handleResponse(final HttpResponse response)
  135. throws ClientProtocolException, IOException {
  136. int status = response.getStatusLine().getStatusCode();
  137. if (status >= 200 ) { // && status cookies = gcookies.getCookies();
  138. for (Cookie aCookie: cookies) {
  139. String cookieName = aCookie.getName();
  140. if ( !(cookieName.lastIndexOf(tString) == -1) ) {
  141. theAccessToken = aCookie.getValue();
  142. }
  143. }
  144.  
  145. System.out.println("Access Token: " + theAccessToken );
  146. return theAccessToken;
  147. }
  148.  
  149. PUT
  150.  
  151. DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
  152. DbxRequestConfig config = new DbxRequestConfig(
  153. "JavaTutorial/1.0", Locale.getDefault().toString());
  154. DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
  155. authorizeUrl = webAuth.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement