informatica:linux:java:maven
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| informatica:linux:java:maven [2016/06/28 12:54] – jose | informatica:linux:java:maven [2017/07/26 11:49] (current) – [Proyecto POST] jose | ||
|---|---|---|---|
| Line 44: | Line 44: | ||
| < | < | ||
| </ | </ | ||
| + | </ | ||
| + | |||
| + | También podemos añadir la versión de java, me daba algún error porque era la 5 por defecto: | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| </ | </ | ||
| Line 49: | Line 57: | ||
| mkdir -p src/ | mkdir -p src/ | ||
| + | |||
| + | El nombre del fichero .java, en este caso Main es la clase que declaramos en el código fuente | ||
| src/ | src/ | ||
| < | < | ||
| Line 95: | Line 105: | ||
| < | < | ||
| - | package | + | package |
| - | import java.io.*; | + | import java.io.BufferedReader; |
| - | import java.net.*; | + | import java.io.DataOutputStream; |
| + | import java.io.InputStreamReader; | ||
| + | import java.net.HttpURLConnection; | ||
| + | import java.net.URL; | ||
| - | public class Main { | + | import javax.net.ssl.HttpsURLConnection; |
| - | public static void main(String[] args) throws IOException { | + | |
| - | String url = " | + | |
| - | String charset = " | + | |
| - | String q = " | + | |
| - | String query = String.format(" | + | public class HttpURLConnectionExample { |
| - | // | + | private final String USER_AGENT = " |
| - | URLConnection connection = new URL(url + "?" + query).openConnection(); | + | |
| - | connection.setDoOutput(true); | + | public static void main(String[] args) throws Exception { |
| - | connection.setRequestProperty(" | + | |
| - | connection.setRequestProperty(" | + | |
| - | try (OutputStream output | + | HttpURLConnectionExample http = new HttpURLConnectionExample(); |
| - | | + | |
| - | | + | System.out.println(" |
| - | ioe.printStackTrace(); | + | http.sendPost(); |
| - | //return | + | |
| - | } | + | } |
| - | | + | |
| - | } | + | // HTTP POST request |
| + | private void sendPost() throws Exception | ||
| + | |||
| + | String url = " | ||
| + | URL obj = new URL(url); | ||
| + | HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); | ||
| + | |||
| + | //add reuqest header | ||
| + | con.setRequestMethod(" | ||
| + | con.setRequestProperty(" | ||
| + | con.setRequestProperty(" | ||
| + | | ||
| + | |||
| + | | ||
| + | String urlParameters = " | ||
| + | |||
| + | // 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(" | ||
| + | System.out.println(" | ||
| + | System.out.println(" | ||
| + | |||
| + | 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()); | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ====== Proyecto Out Of Memory OOM ====== | ||
| + | < | ||
| + | public class TestOOM | ||
| + | { | ||
| + | public static void main(String ar[]) | ||
| + | { | ||
| + | String test[]=new String[Integer.MAX_VALUE]; | ||
| + | for(int i=0; | ||
| + | { | ||
| + | test[i]=" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| ====== Monitorizar con javamelody ====== | ====== Monitorizar con javamelody ====== | ||
informatica/linux/java/maven.1467118477.txt.gz · Last modified: by jose
