Advertisement
Guest User

post idea

a guest
Oct 9th, 2012
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static String postData(String title, String story_bhnd_idea,
  2.             String idea_dtls, int spinnerBudgetId, int spinnerFounderIndexId,
  3.             int spinnercategoryIndexId) {
  4.  
  5.         final String url = "URL will be here";
  6.          
  7.          // Convert the string values into the JSON OBJECT with jsonPostIdea object
  8.                            
  9.                     HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
  10.                    
  11.                      HttpResponse response;
  12.  
  13.                     try{
  14.                        
  15.                         HttpPost post = new HttpPost(url);
  16.                          
  17.                         System.out.println("========VALUE FO THE WHOLE POST IDEA PAGE : === >>>>>>>>  === jsonPostIdea.toString() =====>"+jsonPostIdea.toString());
  18.                         StringEntity se = new StringEntity( jsonPostIdea.toString());
  19.                         se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
  20.                        
  21.                         post.setEntity(se);
  22.                          
  23.                         response = client.execute(post);
  24.                        
  25.                        
  26.                         int statusCode = response.getStatusLine().getStatusCode();
  27.                         System.out.println("=========> statusCode POST IDEA : ===== => " + statusCode);
  28.                        
  29.                         if (statusCode == HttpStatus.SC_OK) {
  30.                             HttpEntity entity = response.getEntity();
  31.                             InputStream is = entity.getContent();
  32.                            
  33.                             String streamValue = iStream_to_String(is);
  34.                            
  35.                             if (entity != null) {
  36.                                
  37.                                 //post.abort();
  38.                                
  39.                                 //response.getEntity().consumeContent();
  40.                             //  EntityUtils.consume(entity);
  41.                                
  42.                                 /*if(entity.getContentLength() > Constants.HTTP.MAX_APP_CONTENT_LENGTH) {
  43.                                        throw new IllegalArgumentException("HTTP entity too large.");                            
  44.                                     }
  45.                                 String result = EntityUtils.toString(entity,"UTF-8");*/
  46.                                 EntityUtils.consume(entity);                
  47.                                 is.close();
  48.                                
  49.                             }
  50.                            
  51.                             return streamValue;
  52.                            
  53.                         } else {
  54.                             return "Hello This is status ==> :"
  55.                                     + String.valueOf(statusCode);
  56.                         }
  57.                            
  58.                     }
  59.                     catch(Exception e){
  60.                         e.printStackTrace();
  61.                      
  62.                     }
  63.                    
  64.             return url;      
  65.  
  66.     }
  67.      
  68.     public static String iStream_to_String(InputStream is1) {
  69.         BufferedReader rd = new BufferedReader(new InputStreamReader(is1), 4096);
  70.        
  71.          
  72.         String line;
  73.         StringBuilder sb = new StringBuilder();
  74.         try {
  75.             while ((line = rd.readLine()) != null) {
  76.                 sb.append(line);
  77.             }
  78.             rd.close();
  79.  
  80.         } catch (IOException e) {
  81.             // TODO Auto-generated catch block
  82.             e.printStackTrace();
  83.         }
  84.         String contentOfMyInputStream = sb.toString();
  85.         return contentOfMyInputStream;
  86.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement