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
| private StringBuffer performSend() {
HttpConnection httpClient = null;
OutputStream os = null;
InputStream is = null;
// String url = "http://localhost:8080/Serveur/Servlet";
String url= "http://localhost:8084/WebTracking/Serveur";
StringBuffer response = null;
try {
httpClient = (HttpConnection) Connector.open(url, Connector.READ_WRITE, true);
httpClient.setRequestMethod(HttpConnection.POST);
httpClient.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");
httpClient.setRequestProperty("CONTENT-TYPE", "application/x-www-form-urlencoded");
httpClient.setRequestProperty("Connection", "close");
os = httpClient.openOutputStream();
os.write(latf.getString().getBytes());
os.write(logf.getString().getBytes());
os.write(altf.getString().getBytes());
os.write(vitesse.getString().getBytes());
os.write(temps.getString().getBytes());
os.write(idclient.getBytes());
int ch = 0;
if(httpClient.getResponseCode() != HttpConnection.HTTP_OK) {
System.err.println("Server returned error: " + httpClient.getResponseCode() + " - " + httpClient.getResponseMessage());
} else if(httpClient.getResponseCode() == HttpConnection.HTTP_OK) {
if(is == null)
is = httpClient.openInputStream();
response = new StringBuffer();
while ((ch = is.read()) != -1) {
response.append((char) ch);
}
}
httpClient.close();
}
catch (Exception e) {System.out.print("errrrrrrrrr"+e.toString());}
finally {
if(os != null) {
try{
os.close();
} catch (IOException e) {
} finally {
os = null;
}
}
if(httpClient != null) {
try {
httpClient.close();
} catch (IOException e) {
} finally {
httpClient = null;
}
}
}
return response;
} |
Partager