Advertisement
Guest User

Erreur avec IOException e

a guest
Feb 24th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package calaos.android;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.UnsupportedEncodingException;
  6. import java.util.Scanner;
  7. import org.apache.http.HttpEntity;
  8. import org.apache.http.client.HttpClient;
  9. import org.apache.http.client.methods.HttpPost;
  10. import org.apache.http.entity.ByteArrayEntity;
  11. import org.apache.http.impl.client.DefaultHttpClient;
  12. import org.apache.http.params.BasicHttpParams;
  13. import org.json.JSONException;
  14. import org.json.JSONObject;
  15.  
  16. public class CJson {
  17.  
  18.     private String m_url;
  19.    
  20.     CJson(String url)
  21.     {
  22.         this.m_url = url;
  23.     }
  24.    
  25.     public JSONObject queryJsonPost(String params)
  26.     {
  27.         JSONObject jsonreponse = null;
  28.         try {
  29.             HttpClient client = new DefaultHttpClient(new BasicHttpParams());
  30.             HttpPost request = new HttpPost(this.m_url);
  31.  
  32.             request.setEntity(new ByteArrayEntity(params.getBytes("UTF8")));
  33.            
  34.             HttpEntity entity = client.execute(request).getEntity();
  35.            
  36.             if (entity != null) {
  37.                 InputStream instream = entity.getContent();
  38.                 String result = new Scanner(instream).next();
  39.                
  40.                 jsonreponse = new JSONObject(result);
  41.             }
  42.  
  43.  
  44.         } catch (UnsupportedEncodingException e) {
  45.             // TODO Auto-generated catch block
  46.             e.printStackTrace();
  47.    
  48.         } catch (IOException e) {
  49.             // TODO Auto-generated catch block
  50.             e.printStackTrace(); // erreur! javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
  51.         } catch (JSONException e) {
  52.             // TODO Auto-generated catch block
  53.             e.printStackTrace();
  54.         }
  55.        
  56.         return jsonreponse;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement