"411 Length required"-response from Google Docs Api using Android API 10 and below -



"411 Length required"-response from Google Docs Api using Android API 10 and below -

i developing application android devices, , 1 part of enabling downloading , uploading between users google docs , device storage. problem have i'm getting different behavior between different versions of android api. i've been doing of development on api lvl 10 (android 2.3.3). no problems on virtual device (i don't have real device test api lvl or higher). on device , emulator of api lvl 8 (2.2.x) , below run 411 length required error google docs api when requesting start resumable upload session. not happen when running same application on emulator of api lvl 10.

i developing eclipse , using google api java client 1.4.1-beta communicate docs api. documentation follow google docs api lies here: http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html

according said documentation, start resumable upload session 1 send empty post request. "root" of users google docs address "https://docs.google.com/feeds/upload/create-session/default/private/full" . how set headers (empty-bodied) request:

googleheaders headers = new googleheaders(); headers.contentlength = "0"; headers.gdataversion = "3"; headers.setgooglelogin(authtoken); //headers.contenttype = getmimetype(file); headers.setslugfromfilename(file.getname()); headers.setapplicationname("test"); headers.set("x-upload-content-length", file.length()); headers.set("x-upload-content-type", getmimetype(file)); request.headers = headers;

i should mention libraries utilize http following:

com.google.api.client.googleapis.googleheaders; com.google.api.client.http.httprequest; com.google.api.client.http.httprequestfactory; com.google.api.client.http.httprequestinitializer; com.google.api.client.http.httptransport; com.google.api.client.http.httpresponse; com.google.api.client.http.httpcontent; com.google.api.client.http.javanet.nethttptransport;

i did packet sniffing see headers, , lo , behold, on different versions of android headers not set same way. if noticed, default request supposed sent using https, changed utilize http see headers packet. here results:

using emulator of android api lvl 10:

post /feeds/upload/create-session/default/private/full?convert=false http/1.1 accept-encoding: gzip authorization: **removed** content-length: 0 content-type: text/plain gdata-version: 3 slug: 5mbfile.txt user-agent: test google-api-java-client/1.4.1-beta x-upload-content-length: 5242880 x-upload-content-type: text/plain host: docs.google.com connection: keep-alive

using emulator of api lvl 7:

post /feeds/upload/create-session/default/private/full?convert=false http/1.1 accept-encoding: gzip authorization: **removed** content-type: text/plain gdata-version: 3 slug: 5mbfile.txt user-agent: test google-api-java-client/1.4.1-beta x-upload-content-length: 5242880 x-upload-content-type: text/plain host: docs.google.com connection: keep-alive

notice missing content-length header, case different. explains why 411 response, how solve this? aim same behavior on devices (excluding ones android 1.x reasons not relevant problem), preferably not using version specific code.

i can't think of many suitable solutions apply in code. 1 think of:

transport = new nethttptransport(); transport.defaultheaders.contentlength = integer.tostring(0);

setting headers differently (deprecated) method in api, no avail. actual headers in requests still same.

setting property "0" or integer.tostring(0) makes no difference either (obviously, getting bit desperate here).

so help or suggestions aim in finding solution welcome. provide more code if requested , packet sniffing possible test different solutions. there high possibility bug in google api java client or android. one? if no solution found, don't have deep plenty knowledge of android figure out study (suspected) bug. if suspect culprit indeed not code, share thought on component causing headers set in different way.

thank time,

teemu

edit - algo asked stack trace, here is: http://pastebin.com/ydcclb2p

edit - setting mimetype content, although body empty. tried removing content-type header, no improvement. line commented out in code above.

edit - i've been trying troubleshoot more. stack trace when trying set headers in 2 different ways in same code: h ttp://pastebin.com/nkmfjyb3

headers.contentlength = "0"; headers.set("content-length", "0");

when used @ same time, collide each other. removing either 1 produce similar results before (411 length required docs , in request content-length absent). collision doesn't happen (or not show in stack trace) when using 1 of these , deprecated way ( transport.defaultheaders.contentlength = "0"; ) create request. combination of of aforementioned methods, either there dual-header collision or request doesn't have content-length.

use instead:

httptransport transport = androidhttp.newcompatibletransport();

that's google recommends compatibility api levels picks right implementation based on version of api. don't have implement yourself. i've tested - works both 2.2 , 2.3.

android google-api google-docs-api fragmentation google-api-java-client

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -