-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSenderThread.pde
43 lines (37 loc) · 1.24 KB
/
SenderThread.pde
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
public class SenderThread implements Runnable {
public void run()
{
String urlParameters = "value="+createJsonToSend().toString();
println(urlParameters);
byte[] postData = urlParameters.getBytes( Charset.forName( "UTF-8" ));
int postDataLength = postData.length;
String request = "http://thebit.altervista.org/spaceapps/insertValues.php";
try {
URL url = new URL(request);
HttpURLConnection cox= (HttpURLConnection) url.openConnection();
cox.setDoOutput( true );
cox.setDoInput ( true );
cox.setInstanceFollowRedirects( false );
cox.setRequestMethod( "POST" );
cox.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded");
cox.setRequestProperty( "charset", "utf-8");
cox.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
cox.setUseCaches( false );
DataOutputStream wr = new DataOutputStream( cox.getOutputStream());
try {
wr.write( postData );
wr.close();
println("tutto ok");
println(cox.getResponseCode());
}
catch(Exception e)
{
println("problema1");
}
}
catch(Exception e)
{
println("problema2");
}
}
}