예제 #1
0
 @Override
 public void run() {
   // TODO Auto-generated method stub
   int result;
   String target = myapplication.getlocalhost() + "adduserzaninfo.php";
   HttpPost httprequest = new HttpPost(target);
   List<NameValuePair> paramsList = new ArrayList<NameValuePair>();
   paramsList.add(new BasicNameValuePair("_userid", myapplication.getUserId())); // 本人
   paramsList.add(new BasicNameValuePair("_guid", guid)); // 本人
   paramsList.add(new BasicNameValuePair("_action", gzaction)); // 本人
   try {
     httprequest.setEntity(new UrlEncodedFormEntity(paramsList, "UTF-8"));
     HttpClient HttpClient1 = CustomerHttpClient.getHttpClient();
     HttpResponse httpResponse = HttpClient1.execute(httprequest);
     if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
       String json = EntityUtils.toString(httpResponse.getEntity());
       result = Integer.parseInt(json);
     } else {
       result = 0;
     }
   } catch (UnsupportedEncodingException e1) {
     e1.printStackTrace();
   } catch (ClientProtocolException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
예제 #2
0
    private String getgz() {
      String target = DemoApplication.getInstance().getlocalhost() + "getgznum.php";
      HttpPost httprequest = new HttpPost(target);
      List<NameValuePair> paramsList = new ArrayList<NameValuePair>();

      System.out.println("gzpos:" + pos);
      System.out.println("gzpos:" + adapter.list.get(pos).get("guid").toString());

      paramsList.add(new BasicNameValuePair("_guid", adapter.list.get(pos).get("guid").toString()));
      String nums = "0";
      try {
        httprequest.setEntity(new UrlEncodedFormEntity(paramsList, "UTF-8"));
        HttpClient HttpClient1 = CustomerHttpClient.getHttpClient();
        HttpClient1.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000);
        HttpClient1.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
        HttpResponse httpResponse = HttpClient1.execute(httprequest);
        if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
          InputStream jsonStream = httpResponse.getEntity().getContent();
          byte[] data = null;
          try {
            data = StreamTool.read(jsonStream);
          } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
          }
          String JsonContext = new String(data);
          if (JsonContext.length() > 0) {
            JSONArray arr = new JSONArray(JsonContext);
            JSONObject jsonobj = arr.getJSONObject(0);
            nums = jsonobj.getString("nums");
          }
        }
      } catch (ClientProtocolException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      return nums;
    }