Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the difference between httpconnection on J2ME and HttpUrlConnection on Android (http error 401)
    primarykey
    data
    text
    <p>I connect to two servers (PROD is https, test server is http) on my applicaitons.</p> <p>on J2ME: I can connect to this two servers without a problem. on Android I can't connect to test-server. When connection is http, if I dont use <code>setChunkedStreamingMode</code>, I cant get <code>responseCode(StringIndexOutOfBoundsException);</code> if I use <code>setChunkedStreamingMode</code>, response code is <code>401</code>. What should I do, where is my fault??</p> <p>Here is my android code, Also if you want to see J2me code, I can add it, too.</p> <pre><code>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(); </code></pre> <p>J2ME code:</p> <pre><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) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload