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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| package titrage;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Vector;
public class httpPost extends Thread
{
private String a;
public void lancement()
{
run();
return;
}
public void run()
{
// ------------------------------------------
String ENCODING = "UTF-8";
try {
StringBuffer sbContent = new StringBuffer();
// les parametres
sbContent.append("texte_entree=");
sbContent.append(URLEncoder.encode("mon premier texte que j'ajoute a cette partie.", ENCODING));
sbContent.append("&Services=");
sbContent.append(URLEncoder.encode("anfr", ENCODING));
sbContent.append("&FormeSortie=");
sbContent.append(URLEncoder.encode("desstx", ENCODING));
// URL sans parametres
URL url = new URL("http://www.lirmm.fr/~chauche/cgi-bin/runsygmart.cgi");
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
// configuration de la connection
httpURLConnection.setUseCaches(false);
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
// par la methode POST
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// envoie de la requête
DataOutputStream stream = new DataOutputStream(httpURLConnection.getOutputStream());
stream.writeBytes(sbContent.toString());
stream.flush();
stream.close();
// recuperation du resultat
InputStream inputStream = httpURLConnection.getInputStream();
for(int c = inputStream.read() ; c!=-1 ; c= inputStream.read()){
System.out.print((char)c);
}
inputStream.close();
} catch (Throwable t) {
}
}
public String getChaine_a()
{
return a;
}
} |
Partager