Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String postData(String title, String story_bhnd_idea,
- String idea_dtls, int spinnerBudgetId, int spinnerFounderIndexId,
- int spinnercategoryIndexId) {
- final String url = "URL will be here";
- // Convert the string values into the JSON OBJECT with jsonPostIdea object
- HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
- HttpResponse response;
- try{
- HttpPost post = new HttpPost(url);
- System.out.println("========VALUE FO THE WHOLE POST IDEA PAGE : === >>>>>>>> === jsonPostIdea.toString() =====>"+jsonPostIdea.toString());
- StringEntity se = new StringEntity( jsonPostIdea.toString());
- se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
- post.setEntity(se);
- response = client.execute(post);
- int statusCode = response.getStatusLine().getStatusCode();
- System.out.println("=========> statusCode POST IDEA : ===== => " + statusCode);
- if (statusCode == HttpStatus.SC_OK) {
- HttpEntity entity = response.getEntity();
- InputStream is = entity.getContent();
- String streamValue = iStream_to_String(is);
- if (entity != null) {
- //post.abort();
- //response.getEntity().consumeContent();
- // EntityUtils.consume(entity);
- /*if(entity.getContentLength() > Constants.HTTP.MAX_APP_CONTENT_LENGTH) {
- throw new IllegalArgumentException("HTTP entity too large.");
- }
- String result = EntityUtils.toString(entity,"UTF-8");*/
- EntityUtils.consume(entity);
- is.close();
- }
- return streamValue;
- } else {
- return "Hello This is status ==> :"
- + String.valueOf(statusCode);
- }
- }
- catch(Exception e){
- e.printStackTrace();
- }
- return url;
- }
- public static String iStream_to_String(InputStream is1) {
- BufferedReader rd = new BufferedReader(new InputStreamReader(is1), 4096);
- String line;
- StringBuilder sb = new StringBuilder();
- try {
- while ((line = rd.readLine()) != null) {
- sb.append(line);
- }
- rd.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String contentOfMyInputStream = sb.toString();
- return contentOfMyInputStream;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement