dropbox / dropbox-sdk-java

A Java library for the Dropbox Core API.
https://www.dropbox.com/developers/documentation/java
MIT License
595 stars 449 forks source link

how to set socks5 proxy in http request #83

Closed marksnoopy closed 2 years ago

marksnoopy commented 8 years ago

i can not find how to set socks5 proxy in http request , it supports or not ?

marksnoopy commented 8 years ago

i find some ways to reslove it like this .

Config config = Config.builder().withProxy(<PROXY>).build();
StandardHttpRequestor requ = new StandardHttpRequestor(config);

DbxRequestConfig dbxRequestConfig = DbxRequestConfig.newBuilder("test").withHttpRequestor(requ).build();
DbxClientV2 client = new DbxClientV2(dbxRequestConfig, <ACCESS_TOKEN>);

<PROXY> is a socks proxy and it is available. <ACCESS_TOKEN> is access token.

run and report error, what wrong ?

Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:912)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1294)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1321)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1305)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:523)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1087)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
        at com.dropbox.core.http.StandardHttpRequestor.getOutputStream(StandardHttpRequestor.java:123)
        at com.dropbox.core.http.StandardHttpRequestor.access$000(StandardHttpRequestor.java:28)
        at com.dropbox.core.http.StandardHttpRequestor$Uploader.<init>(StandardHttpRequestor.java:133)
        at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:72)
        at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:28)
        at com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:232)
        ... 26 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
        at sun.security.ssl.InputRecord.read(InputRecord.java:352)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893)

in addition , i can not understand what is the param clientIdentifier in class DbxRequestConfig .

greg-db commented 8 years ago

The clientIdentifier should be a string that identifies your app and version. We'll update the documentation to clarify this.

For reference, the client identifier is usually of the form "SoftwareName/SoftwareVersion". For example, if you have a project named "PhotoEdit", your might set the client identifier to "PhotoEditServer/1.3" in your server software and to "PhotoEditAndroid/1.8" in your Android app. This value is prepended to the "User-Agent" HTTP header on all requests made to the Dropbox API. This has no effect on the behavior of the Dropbox API, but it may help identify your application when debugging things later.

I'm not sure offhand what the issue with the proxy may be, but we'll take a look.

marksnoopy commented 8 years ago

@greg-db thanks, and i had solved the problme ,it looks fine

marksnoopy commented 8 years ago

i means i set the proxy , but it seems no effets . @greg-db

marksnoopy commented 8 years ago

i use the proxy in google api client sdk and it looks fine

zjiuyang commented 8 years ago

Hey @marksnoopy I just used my local dante server as my proxy, and it worked fine. Can you share more information with us? Do you still see any exception?

handstandsam commented 2 years ago

To setup a proxy, I would recommend using the OkHttp3Requestor https://github.com/dropbox/dropbox-sdk-java/blob/8b7d6b902a2394f0ef27ac53187ba388e6baf280/dropbox-sdk-java/src/main/java/com/dropbox/core/http/OkHttp3Requestor.java. You can pass it a configured OkHttp instance which is set up to use a proxy. The "requestor" is a abstraction layer to allow for multiple Http implementations.