java - HttpURLConnection header max length in Android -


i have following code

update:there problem exists in android apps,it works fine in java application

java (not working large header value)

url url = new url("myurl"); //<===this http://www.google.com   httpurlconnection request = (httpurlconnection) url.openconnection();  string usercredentials = "username:aaaaabbbbbbbbccccsssssssssddddddddddbe4b97cc9e81db"; string basicauth = "basic " +  android.util.base64.encodetostring(             usercredentials.getbytes(), android.util.base64.default); request.setrequestproperty ("authorization", basicauth);  request.connect(); inputstream stream = (inputstream) request.getcontent(); 

i classnotfoundexception when call getcontent()

java.lang.classnotfoundexception: didn't find class "org.apache.harmony.awt.www.content.text.html__charset_us_ascii" on path: dexpathlist[[directory "."],nativelibrarydirectories=[/vendor/lib, /system/lib]] 

in classloader.class line 514

 protected class<?> loadclass(string classname, boolean resolve) throws classnotfoundexception {     class<?> clazz = findloadedclass(classname);       if (clazz == null) {         classnotfoundexception suppressed = null;         try {             clazz = parent.loadclass(classname, false);         } catch (classnotfoundexception e) {             suppressed = e;         }          if (clazz == null) {             try {                 clazz = findclass(classname);             } catch (classnotfoundexception e) {                 e.addsuppressed(suppressed);                //classname=org.apache.harmony.awt.www.content.text.html__charset_us_ascii                 throw e;  //<===the code crashes here              }         }     }      return clazz; } 

the problem size of authorization header,even if not big (88 characters)
if change value of header smaller works.
can change somehow max size of header?

i have tried other platforms (windows ,windows phone ,web ) , works fine,the problem not on server.

jquery (works always)

var usernameandpasword=["username","aaaaabbbbbbbbccccsssssssssddddddddddbe4b97cc9e81db"].join(":"); var authorizationheadervalue="basic "+   window.btoa(usernameandpasword);  $.ajax({     url : "http://...",     type: "get",     beforesend: function (request) {    request.setrequestheader("authorization", authorizationheadervalue); },     success: function(data, textstatus, jqxhr)  {   alert(data +  "\n" + textstatus ); },     error: function (jqxhr, textstatus, errorthrown){ alert(jqxhr.responsetext +  " \n " + textstatus + " \n"+errorthrown); }   });  

c# (works always)

 httpwebrequest request = (httpwebrequest)webrequest.create(requesturistring);  request.method = "get";  request.headers["accept-encoding"] = "gzip, deflate";   var bytes = encoding.utf8.getbytes("username" + ":" + "aaaaabbbbbbbbccccsssssssssddddddddddbe4b97cc9e81db" );  var base64 = convert.tobase64string(bytes);  request.headers["authorization"] = "basic " + base64;   httpwebresponse webresponse = (httpwebresponse)request.getresponseasync().result; 

as using base64 encoding maximum length encoded string should 64, , if mime maximum length encoded string should 76.

for more information please check this


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -