Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown method 'PATCH' #16

Closed
isabsent opened this issue Dec 2, 2015 · 0 comments
Closed

Unknown method 'PATCH' #16

isabsent opened this issue Dec 2, 2015 · 0 comments
Labels

Comments

@isabsent
Copy link
Contributor

isabsent commented Dec 2, 2015

I have included onedrive-sdk-android as a sourse code in my project (minSdkVersion 15) and have got an exception when trying to rename file on the cloud on Android device with API level 16:

Caused by: java.net.ProtocolException: Unknown method 'PATCH'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE]
    at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:677)
    at libcore.net.http.HttpsURLConnectionImpl.setRequestMethod(HttpsURLConnectionImpl.java:144)
    at com.onedrive.sdk.http.UrlConnection.<init>(UrlConnection.java:61)
    at com.onedrive.sdk.http.DefaultConnectionFactory.createFromRequest(DefaultConnectionFactory.java:40)
    at com.onedrive.sdk.http.DefaultHttpProvider.sendRequestInternal(DefaultHttpProvider.java:194) 
    at com.onedrive.sdk.http.DefaultHttpProvider.access$000(DefaultHttpProvider.java:48)
    at com.onedrive.sdk.http.DefaultHttpProvider$1.run(DefaultHttpProvider.java:127)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    at java.lang.Thread.run(Thread.java:856)

The same exception arises when I install onedrive-explorer-android on Android device with API level 16 (changing minSdkVersion to 15) and does not arise on Android device with API level 21. Was this exception the reason to set up minSdkVersion 19 in your onedrive-explorer-android demo project or not? And how to avoid this exception using your SDK as a source code for devices with API level from 15 to 18?

P.S. Please, take a look on X-HTTP-Method-Override. The constructor of your UrlConnection class can be changed to:

public UrlConnection(final IHttpRequest request) throws IOException {
    mConnection = (HttpURLConnection) request.getRequestUrl().openConnection();

    for (final HeaderOption header : request.getHeaders()) {
        mConnection.addRequestProperty(header.getName(), header.getValue());
    }
    if (request.getHttpMethod().equals(HttpMethod.PATCH) && Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        mConnection.setRequestProperty("X-HTTP-Method-Override", "PATCH");
        mConnection.setRequestMethod(HttpMethod.POST.toString());
    } else {
        mConnection.setRequestMethod(request.getHttpMethod().toString());
    }
}

and PATCH request for devices with low API level will be supported untill server supports "X-HTTP-Method-Override" header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants