Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- executing request:GET https://www.dropbox.com/login HTTP/1.1
- ----------------------------------------
- HTTP/1.1 200 OK
- Request Token: moiejtzdLqTA_0sh3gQyNZAI
- executing request:POST https://www.dropbox.com/login HTTP/1.1
- ----------------------------------------
- HTTP/1.1 200 OK
- Access Token: 5Ot52QKDbDPSsL1ApU4MIapJ
- executing request:POST https://dl-web.dropbox.com/upload?
- name=sample.jpg&dest=upload&cookie_t=5Ot52QKDbDP....SsJ&t=5Ot5...apJ HTTP/1.1
- ----------------------------------------
- HTTP/1.1 400 Bad Request
- https://dl-web.dropbox.com/chunked_upload?
- name=tmp1.jpg
- &chunk=0
- &chunks=1
- &bjar=W3sic2Vzc1..............Q%253D%253D
- &blid=AAAw4tn................2cDxA
- &cookie_t=32yq........nw6c34o
- &dest=
- &t=32yqVof........c34o
- &reported_total_size=5611
- &upload_id=1BKGRRP5TpCEjcWSu5tmpQ
- &offset=0
- https://dl-web.dropbox.com/chunked_upload?
- name=tmp1.jpg
- &chunk=0
- &chunks=1
- &bjar=W3sic2Vzc1..............Q%253D%253D
- &blid=AAAw4tn................2cDxA
- &cookie_t=32yq........nw6c34o
- &dest=
- &t=32yqVof........c34o
- &reported_total_size=5611
- &upload_id=1BKGRRP5TpCEjcWSu5tmpQ
- &offset=0
- // constructor ...
- public HttpClientExample() {
- gcookies = new BasicCookieStore();
- globalConfig = RequestConfig.custom()
- .setCookieSpec(CookieSpecs.BEST_MATCH)
- .build();
- // Create local HTTP context
- ghttpContext = HttpClientContext.create();
- ghttpContext.setCookieStore(gcookies);
- //
- redirectStrategy = new LaxRedirectStrategy(); // for http redirect ...
- httpclient = HttpClients.custom()
- .setDefaultRequestConfig(this.globalConfig)
- .setDefaultCookieStore(this.gcookies)
- .setRedirectStrategy(redirectStrategy)
- .build();
- } // constructor ...
- public static void main(String[] args) throws Exception {
- HttpClientExample myhttp = new HttpClientExample();
- try {
- this.localConfig = RequestConfig.copy(this.globalConfig)
- .setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY)
- .build();
- String requestToken = this.getRequestToken(httpclient, loginurl);
- theAccessToken = this.postForAccessToken(requestToken, loginurl);
- String localFileTopassIn = this.localPath ;
- this.postToUpload(httpclient, this.theAccessToken, localFileTopassIn , this.dropboxFolderOnlyName);
- }
- }
- private String getRequestToken(HttpClient client, String theURL) throws Exception {
- HttpGet httpget = new HttpGet(theURL);
- httpget.setConfig(localConfig);
- httpget.setHeader("Connection", "keep-alive");
- System.out.println("nexecuting request:" + httpget.getRequestLine());
- // Create a custom response handler
- ResponseHandler responseHandler = new ResponseHandler() {
- public String handleResponse(final HttpResponse response)
- throws ClientProtocolException, IOException {
- int status = response.getStatusLine().getStatusCode();
- if (status >= 200 ) { // && status cookies = gcookies.getCookies();
- for (Cookie aCookie: cookies) {
- String cookieName = aCookie.getName();
- if ( !(cookieName.lastIndexOf(gvcString) == -1) ) {
- gvc = aCookie.getValue();
- } else if ( !(cookieName.lastIndexOf(tString) == -1) ) {
- requestToken = aCookie.getValue();
- }
- }
- System.out.println("Request Token: " + requestToken );
- return requestToken;
- }
- private String postForAccessToken(HttpClient client, String requestToken, String theURL) throws Exception{
- /*
- * Send a post together with request token and my login to get accessToken ...
- */
- HttpPost httppost = new HttpPost(theURL); // loginurl);
- httppost.setConfig(localConfig);
- ghttpContext.setCookieStore(gcookies);
- List params = new LinkedList();
- params.add(new BasicNameValuePair("login_email", myemail));
- params.add(new BasicNameValuePair("login_password", mypasswd));
- params.add(new BasicNameValuePair("t", requestToken));
- HttpEntity postentity = new UrlEncodedFormEntity(params);
- httppost.setEntity(postentity);
- System.out.println("nexecuting request:" + httppost.getRequestLine());
- // Create a custom response handler
- ResponseHandler responseHandler = new ResponseHandler() {
- public String handleResponse(final HttpResponse response)
- throws ClientProtocolException, IOException {
- int status = response.getStatusLine().getStatusCode();
- if (status >= 200 ) { // && status cookies = gcookies.getCookies();
- for (Cookie aCookie: cookies) {
- String cookieName = aCookie.getName();
- if ( !(cookieName.lastIndexOf(tString) == -1) ) {
- theAccessToken = aCookie.getValue();
- }
- }
- System.out.println("Access Token: " + theAccessToken );
- return theAccessToken;
- }
- PUT
- DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
- DbxRequestConfig config = new DbxRequestConfig(
- "JavaTutorial/1.0", Locale.getDefault().toString());
- DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
- authorizeUrl = webAuth.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement