Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package calaos.android;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.UnsupportedEncodingException;
- import java.util.Scanner;
- import org.apache.http.HttpEntity;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.entity.ByteArrayEntity;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.params.BasicHttpParams;
- import org.json.JSONException;
- import org.json.JSONObject;
- public class CJson {
- private String m_url;
- CJson(String url)
- {
- this.m_url = url;
- }
- public JSONObject queryJsonPost(String params)
- {
- JSONObject jsonreponse = null;
- try {
- HttpClient client = new DefaultHttpClient(new BasicHttpParams());
- HttpPost request = new HttpPost(this.m_url);
- request.setEntity(new ByteArrayEntity(params.getBytes("UTF8")));
- HttpEntity entity = client.execute(request).getEntity();
- if (entity != null) {
- InputStream instream = entity.getContent();
- String result = new Scanner(instream).next();
- jsonreponse = new JSONObject(result);
- }
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace(); // erreur! javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return jsonreponse;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement