java me - What is the difference between httpconnection on J2ME and HttpUrlConnection on Android (http error 401) -
i connect 2 servers (prod https, test server http) on applicaitons.
on j2me: can connect 2 servers without problem. on android can't connect test-server. when connection http, if dont use setchunkedstreamingmode
, cant responsecode(stringindexoutofboundsexception);
if use setchunkedstreamingmode
, response code 401
. should do, fault??
here android code, if want see j2me code, can add it, too.
url url = new url(geturl()); urlconnection conn = url.openconnection(); httpurlconnection httpconn = (httpurlconnection) conn; httpconn.setallowuserinteraction(false); httpconn.setinstancefollowredirects(true); httpconn.setconnecttimeout(10000); httpconn.setrequestproperty("user-agent", util.getdevicefullmodel() + " " + util.getsoftwareversion()); httpconn.setrequestproperty("accept-charset", "utf-8"); httpconn.setrequestproperty("content-type", "text/xml; charset=utf-8"); httpconn.setrequestproperty("soapaction", "http://tempuri.org/iauthenticationserviceforgroup/"+contypestring); httpconn.setrequestproperty("software-version", appdata.version); httpconn.setchunkedstreamingmode(getparams().getbytes("utf8").length); httpconn.setrequestmethod("post"); httpconn.setdooutput(true); httpconn.setdoinput(true); httpconn.connect(); os = httpconn.getoutputstream(); os.write(getparams().getbytes("utf8")); try { os.close(); } catch (exception e) { onerror(e); } response=httpconn.getresponsecode();
j2me code:
httpconnection c = (httpconnection)xconnection.openconnection(xconnection.server + "authenticationserviceforgroup.svc"); c.setrequestproperty("user-agent", xutil.getdevicefullmodel() + " " + xutil.getsoftwareversion()); c.setrequestproperty("content-type", "text/xml; charset=utf-8"); c.setrequestproperty("soapaction", "http://tempuri.org/iauthenticationserviceforgroup/"+contype); c.setrequestproperty("software-version", xapp.version); c.setrequestmethod(httpconnection.post); outputstream os = null; os = c.openoutputstream(); os.write(sparams.getbytes()); try {os.close();} catch (exception e) {} if (c.getresponsecode() == httpconnection.http_ok)
if you're using pre-2.3 devices, httpurlconnection has known issues
http://android-developers.blogspot.com/2011/09/androids-http-clients.html
Comments
Post a Comment