• EnglishSpanishGermanFrenchPolishChinese (Traditional)


EnglishSpanishGermanFrenchPolishChinese (Traditional)

Operating systems, scripting, PowerShell and security

Operating systems, software development, scripting, PowerShell tips, network and security

Menú principal
  • Categorías
  • Cursos
  • Libro de PowerShell
  • Lo mejor
  • Lo último
  • Proyectos
  • Contactar
Ir al contenido

Realizar petición HTTP mediante el método POST utilizando librerías de Apache

Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*Importar librerías:
commons-codec
commons-httpclient
commons-logging
*/
 
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class MetodoPOST {
public static void main(String args[]) {
HttpClient client = new HttpClient();
client.getParams().setParameter("http.useragent", "");
BufferedReader br = null;
 
PostMethod method = new PostMethod("https://www.jesusninoc.com/getypost/examplepost.php");
method.addParameter("nombre", "Juan");
method.addParameter("edad", "34");
try{
int returnCode = client.executeMethod(method);
if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
System.err.println("Método POST no implementado");
// still consume the response body
method.getResponseBodyAsString();
} else {
br = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
String readLine;
while(((readLine = br.readLine()) != null)) {
System.err.println(readLine);
}
}
} catch (Exception e) {
System.err.println(e);
} finally {
method.releaseConnection();
if(br != null) try { br.close(); } catch (Exception fe) {}
}
}
}

post

Publicado el día 26 de enero de 2016

CATEGORÍAS

Java, PHP

ETIQUETAS

Apache, client, Connect, HTTP, HTTPS, Java, java.io.BufferedReader, java.io.InputStreamReader, Jesús Niño Camazón, Methods, User, UserAgent

MÁS

  • Ejecutar un script de PowerShell desde Java
  • Realizar petición HTTP mediante el método GET
  • Sincronización de productor y consumidor con hilos en Java
  • Usar XML:DB API para ejecutar una consulta de base de datos con XPath en el servidor eXist-db
  • Cifrar y descifrar con RSA utilizando ECB desde Java (generando clave privada y clave pública)
  • Cifrar y descifrar con AES desde Java (con clave aleatoria)