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";
- JSONObject jsonPostIdea = new JSONObject();
- JSONObject JSONStoryBhndIdea = new JSONObject();
- JSONArray jsonArrayStoryBhndIdea = new JSONArray();
- try {
- JSONStoryBhndIdea.put("value", story_bhnd_idea);
- jsonArrayStoryBhndIdea.put(JSONStoryBhndIdea);
- System.out.println("=============> value of the Story Behind Idea:"+jsonArrayStoryBhndIdea.toString());
- }
- catch (Exception e) {
- }
- JSONObject JSONIdeaDetails = new JSONObject();
- JSONArray jsonArrayIdeaDetails = new JSONArray();
- try {
- JSONIdeaDetails.put("value", idea_dtls);
- jsonArrayIdeaDetails.put(JSONIdeaDetails);
- System.out.println("=============> value of the Idea details:"+jsonArrayIdeaDetails.toString());
- }
- catch (Exception e) {
- }
- JSONObject JSONBudget = new JSONObject();
- JSONArray jsonArrayBudget = new JSONArray();
- try {
- JSONBudget.put("value", ""+spinnerBudgetId);
- jsonArrayBudget.put(JSONBudget);
- System.out.println("=============> value of the Budget:"+jsonArrayBudget.toString());
- }
- catch (Exception e) {
- }
- JSONObject JSONMyFounder = new JSONObject();
- JSONArray jsonArrayMyFounder = new JSONArray();
- try {
- JSONMyFounder.put("nid", ""+spinnerFounderIndexId);
- jsonArrayMyFounder.put(JSONMyFounder);
- System.out.println("=============> value of the My Founder:"+jsonArrayMyFounder);
- }
- catch (Exception e) {
- }
- JSONObject JSONCategory = new JSONObject();
- try {
- JSONObject Json = new JSONObject();
- Json.put("tid", ""+spinnercategoryIndexId);
- JSONCategory.put(""+spinnercategoryIndexId, Json);
- System.out.println("=============> value of the category :"+JSONCategory);
- }
- catch (Exception e) {
- }
- /**
- * JSONObject For the post idea
- */
- try {
- jsonPostIdea.put("type","idea");
- jsonPostIdea.put("title", title);
- jsonPostIdea.put("field_story_idea", jsonArrayStoryBhndIdea);
- jsonPostIdea.put("field_founder_profile_refrence", jsonArrayMyFounder);
- jsonPostIdea.put("field_idea_budget", jsonArrayBudget);
- jsonPostIdea.put("field_idea_details", jsonArrayIdeaDetails);
- jsonPostIdea.put("taxonomy", JSONCategory);
- System.out.println("========VALUE FO THE WHOLE POST IDEA PAGE : === >>>>>>>> ========>"+jsonPostIdea.toString());
- } catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- 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