Title: Java code breaks
Last modified: August 21, 2016

---

# Java code breaks

 *  [Mudassir Shahzad](https://wordpress.org/support/users/mudassir-shahzad/)
 * (@mudassir-shahzad)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/java-code-breaks/)
 * I am trying to post this code to my wordpress blog but the page shows blank.
 *     ```
       <pre class="lang:java decode:false">package com.mudassirshahzad;
   
       import java.io.BufferedReader;
       import java.io.DataOutputStream;
       import java.io.InputStreamReader;
       import java.net.HttpURLConnection;
       import java.net.URL;
   
       import javax.net.ssl.HttpsURLConnection;
   
       public class HttpURLConnectionExample {
   
       	private final String USER_AGENT = "Mozilla/5.0";
   
       	public static void main(String[] args) throws Exception {
   
       		HttpURLConnectionExample http = new HttpURLConnectionExample();
   
       		System.out.println("Testing 1 - Send Http GET request");
       		http.sendGet();
   
       		System.out.println("\nTesting 2 - Send Http POST request");
       		http.sendPost();
   
       	}
   
       	// HTTP GET request
       	private void sendGet() throws Exception {
   
       		String url = "http://www.google.com/search?q=mkyong";
   
       		URL obj = new URL(url);
       		HttpURLConnection con = (HttpURLConnection) obj.openConnection();
   
       		// optional default is GET
       		con.setRequestMethod("GET");
   
       		//add request header
       		con.setRequestProperty("User-Agent", USER_AGENT);
   
       		int responseCode = con.getResponseCode();
       		System.out.println("\nSending 'GET' request to URL : " + url);
       		System.out.println("Response Code : " + responseCode);
   
       		BufferedReader in = new BufferedReader(
       		        new InputStreamReader(con.getInputStream()));
       		String inputLine;
       		StringBuffer response = new StringBuffer();
   
       		while ((inputLine = in.readLine()) != null) {
       			response.append(inputLine);
       		}
       		in.close();
   
       		//print result
       		System.out.println(response.toString());
   
       	}
   
       	// HTTP POST request
       	private void sendPost() throws Exception {
   
       		String url = "https://selfsolve.apple.com/wcResults.do";
       		URL obj = new URL(url);
       		HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
   
       		//add reuqest header
       		con.setRequestMethod("POST");
       		con.setRequestProperty("User-Agent", USER_AGENT);
       		con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
   
       		String urlParameters = "sn=C02G8416DRJM&cn=&locale=&caller=&num=12345";
   
       		// Send post request
       		con.setDoOutput(true);
       		DataOutputStream wr = new DataOutputStream(con.getOutputStream());
       		wr.writeBytes(urlParameters);
       		wr.flush();
       		wr.close();
   
       		int responseCode = con.getResponseCode();
       		System.out.println("Sending 'POST' request to URL : " + url);
       		System.out.println("Post parameters : " + urlParameters);
       		System.out.println("Response Code : " + responseCode);
   
       		BufferedReader in = new BufferedReader(
       		        new InputStreamReader(con.getInputStream()));
       		String inputLine;
       		StringBuffer response = new StringBuffer();
   
       		while ((inputLine = in.readLine()) != null) {
       			response.append(inputLine);
       		}
       		in.close();
   
       		//print result
       		System.out.println(response.toString());
   
       	}
   
       }
   
       <pre class="lang:java decode:false">package com.mudassirshahzad;
       import java.io.BufferedReader;
       import java.io.InputStreamReader;
       import java.util.ArrayList;
       import java.util.List;
   
       import org.apache.http.HttpResponse;
       import org.apache.http.NameValuePair;
       import org.apache.http.client.HttpClient;
       import org.apache.http.client.entity.UrlEncodedFormEntity;
       import org.apache.http.client.methods.HttpGet;
       import org.apache.http.client.methods.HttpPost;
       import org.apache.http.impl.client.DefaultHttpClient;
       import org.apache.http.message.BasicNameValuePair;
   
       public class HttpClientExample {
   
       private final String USER_AGENT = "Mozilla/5.0";
   
       public static void main(String[] args) throws Exception {
   
       HttpClientExample http = new HttpClientExample();
   
       System.out.println("Testing 1 - Send Http GET request");
       http.sendGet();
   
       System.out.println("\nTesting 2 - Send Http POST request");
       http.sendPost();
   
       }
   
       // HTTP GET request
       private void sendGet() throws Exception {
   
       String url = "http://www.google.com/search?q=developer";
   
       HttpClient client = new DefaultHttpClient();
       HttpGet request = new HttpGet(url);
   
       // add request header
       request.addHeader("User-Agent", USER_AGENT);
   
       HttpResponse response = client.execute(request);
   
       System.out.println("\nSending 'GET' request to URL : " + url);
       System.out.println("Response Code : " +
       response.getStatusLine().getStatusCode());
   
       BufferedReader rd = new BufferedReader(
       new InputStreamReader(response.getEntity().getContent()));
   
       StringBuffer result = new StringBuffer();
       String line = "";
       while ((line = rd.readLine()) != null) {
       result.append(line);
       }
   
       System.out.println(result.toString());
   
       }
   
       // HTTP POST request
       private void sendPost() throws Exception {
   
       String url = "https://selfsolve.apple.com/wcResults.do";
   
       HttpClient client = new DefaultHttpClient();
       HttpPost post = new HttpPost(url);
   
       post.setHeader("User-Agent", USER_AGENT);
   
       List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
       urlParameters.add(new BasicNameValuePair("sn", "C02G8416DRJM"));
       urlParameters.add(new BasicNameValuePair("cn", ""));
       urlParameters.add(new BasicNameValuePair("locale", ""));
       urlParameters.add(new BasicNameValuePair("caller", ""));
       urlParameters.add(new BasicNameValuePair("num", "12345"));
   
       post.setEntity(new UrlEncodedFormEntity(urlParameters));
   
       HttpResponse response = client.execute(post);
       System.out.println("\nSending 'POST' request to URL : " + url);
       System.out.println("Post parameters : " + post.getEntity());
       System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
   
       BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
   
       StringBuffer result = new StringBuffer();
       String line = "";
       while ((line = rd.readLine()) != null) {
       result.append(line);
       }
   
       System.out.println(result.toString());
   
       }
   
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  [edvardtoth](https://wordpress.org/support/users/edvardtoth/)
 * (@edvardtoth)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/java-code-breaks/#post-4444632)
 * This is caused simply by the size of the code sample. I started running into 
   the same issue after 2.4.1 – code beyond a certain length yields a blank page.
   Smaller chunks of code still work fine (you can confirm this by trying to use
   a small section of this code).
 * I don’t know, must be a memory-management issue or something along those lines.
   There’s no feedback or acknowledgement, one can only hope that it will be fixed
   at some point, as the plugin is currently useless.

Viewing 1 replies (of 1 total)

The topic ‘Java code breaks’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/crayon-syntax-highlighter_b0c4c0.
   svg)
 * [Crayon Syntax Highlighter](https://wordpress.org/plugins/crayon-syntax-highlighter/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/crayon-syntax-highlighter/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/crayon-syntax-highlighter/)
 * [Active Topics](https://wordpress.org/support/plugin/crayon-syntax-highlighter/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/crayon-syntax-highlighter/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/crayon-syntax-highlighter/reviews/)

## Tags

 * [crayon](https://wordpress.org/support/topic-tag/crayon/)
 * [java](https://wordpress.org/support/topic-tag/java/)

 * 1 reply
 * 2 participants
 * Last reply from: [edvardtoth](https://wordpress.org/support/users/edvardtoth/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/java-code-breaks/#post-4444632)
 * Status: not resolved