Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTP request fails with timeout android
    primarykey
    data
    text
    <p>i am learning connect server with http client, but when i am request data, usualy fail and timeout, how to fix it ?</p> <p>this my code</p> <pre><code>public void detailURL(String url) { Log.v("Android Spinner JSON Data Activity", url); mTask=new Detail().execute(url); } private class Detail extends AsyncTask&lt;String, Void, String&gt; { private static final int REGISTRATION_TIMEOUT = 3 * 1000; private static final int WAIT_TIMEOUT = 30 * 1000; private final HttpClient httpclient = new DefaultHttpClient(); final HttpParams params = httpclient.getParams(); HttpResponse response; private String content = null; private boolean error = false; private ProgressDialog dialog = new ProgressDialog(ProfileActivity.this); protected void onPreExecute() { dialog.setMessage("Getting your data... Please wait..."); } protected String doInBackground(String... urls) { String URL = null; try { URL = urls[0]; HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, WAIT_TIMEOUT); ConnManagerParams.setTimeout(params, WAIT_TIMEOUT); ByteArrayOutputStream bos = new ByteArrayOutputStream(); photo.compress(Bitmap.CompressFormat.JPEG, 100, bos); byte[] data = bos.toByteArray(); ByteArrayBody bab = new ByteArrayBody(data,file_name); HttpPost httpPost = new HttpPost(URL); //add name value pair for the country code MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); reqEntity.addPart("foto", bab); reqEntity.addPart("tag", new StringBody(register_tag)); reqEntity.addPart("name", new StringBody(name)); reqEntity.addPart("email", new StringBody(email)); reqEntity.addPart("namalengkap", new StringBody(namalengkap)); reqEntity.addPart("telepon", new StringBody(telepon)); reqEntity.addPart("val_lokasi_alamat", new StringBody(val_lokasi_alamat)); httpPost.setEntity(reqEntity); response = httpclient.execute(httpPost); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK) { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); content = out.toString(); } else{ //Closes the connection. Log.w("HTTP1:",statusLine.getReasonPhrase()); response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { Log.w("HTTP2:",e ); content = e.getMessage(); error = true; cancel(true); } catch (IOException e) { Log.w("HTTP3:",e ); content = e.getMessage(); error = true; cancel(true); } catch (Exception e) { Log.w("HTTP4:",e ); content = e.getMessage(); error = true; cancel(true); } return content; } protected void onCancelled() { mTask.cancel(true); btn_enable(); ProgressLoadStartRegister.setVisibility(View.GONE); statusKoneksi(); } protected void onPostExecute(String content) { if (error) { mTask.cancel(true); ProgressLoadStartRegister.setVisibility(View.GONE); btn_enable(); statusKoneksi(); // getUpdate(); } else { ProgressLoadStartRegister.setVisibility(View.GONE); displaystatis_kontenDetail(content); mTask.cancel(true); btn_enable(); } } } private void displaystatis_kontenDetail(String response){ JSONObject json = null; try { json = new JSONObject(response); Log.d("json", json.toString()); if (json.getString(KEY_SUCCESS) != null) { String res = json.getString(KEY_SUCCESS); if(Integer.parseInt(res) == 1){ GCMRegistrar.setRegisteredOnServer(getApplicationContext(), true); // user successfully registred // Store user details in SQLite Database Intent LoginActivity = new Intent(getApplicationContext(), LoginActivity.class); // Close all views before launching Dashboard LoginActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(LoginActivity); // Close Registration Screen finish(); Toast.makeText(getApplicationContext(), "Silakan cek kotak masuk atau spam email anda untuk konfirmasi keaktifan akun",Toast.LENGTH_LONG).show(); } else { // Error in registration Toast.makeText(getApplicationContext(), "Username atau Email sudah terdaftar",Toast.LENGTH_SHORT).show(); } } } catch (JSONException e) { e.printStackTrace(); } } private void statusKoneksi(){ statusKoneksiRegister.setVisibility(View.VISIBLE); statusKoneksiRegister.startAnimation(animstatuskoneksi); handler = new Handler(); handler.postDelayed(new Runnable(){ @Override public void run(){ statusKoneksiRegister.setVisibility(View.GONE); statusKoneksiRegister.clearAnimation(); } }, 4500); } </code></pre> <p>usualy <strong>error = true;</strong></p> <pre><code>protected void onPostExecute(String content) { if (error) { mTask.cancel(true); ProgressLoadStartRegister.setVisibility(View.GONE); btn_enable(); statusKoneksi(); //getUpdate(); } else { ProgressLoadStartRegister.setVisibility(View.GONE); displaystatis_kontenDetail(content); mTask.cancel(true); btn_enable(); } } </code></pre> <p>this permession in my manifest </p> <pre><code>&lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; &lt;!-- GCM connects to Internet Services. --&gt; &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; &lt;!-- GCM requires a Google account. --&gt; &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt; &lt;!-- Keeps the processor from sleeping when a message is received. --&gt; &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt; &lt;!-- Creates a custom permission so only this app can receive its messages. --&gt; &lt;permission android:name="com.droidersuin.project.permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt; &lt;uses-permission android:name="com.droidersuin.project.permission.C2D_MESSAGE" /&gt; &lt;!-- This app has permission to register and receive data message. --&gt; &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt; &lt;!-- Network State Permissions to detect Internet status --&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; &lt;!-- Permission to vibrate --&gt; &lt;uses-permission android:name="android.permission.VIBRATE" /&gt; &lt;uses-permission android:name="android.permission.WRITE_SETTINGS"/&gt; &lt;permission android:name="com.droidersuin.project.permission.MAPS_RECEIVE" android:protectionLevel="signature" /&gt; &lt;uses-permission android:name="com.droidersuin.project.permission.MAPS_RECEIVE" /&gt; &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt; &lt;!-- Required to show current location --&gt; &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_GPS"/&gt; &lt;uses-permission android:name="android.permission.CAMERA"/&gt; </code></pre> <p>sorry with my english, thanks your participant ... :)</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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