Creating a web client to submit data to SQL

I’ve been looking for quite a long time for how to create a « http client » that could pass data as with the POST method from a Tini. That way, I’ll be able to send data to be logged to the linux webserver and then, with a PHP page, I’ll send data to the SQL database.

Here’s an example I found on Dallas Semiconductor Forums. By the way, be sure to register and spend a lot of time reading over there. There’s a lot of information.

I have an example of my own… see if this one helps
in my case I’m sure there’s no data above the 300 bytes- you might need to make a loop in your case to keep reading until no data is left – or a timeout.


private boolean HTTPData() {

try {
URL url = new URL("http", Config.ServerIP(), 80, "/engine.asp");
Connection http = new Connection(url);

byte[] datain = new byte[300];
int data_count;

http.setRequestMethod("POST");
http.setRequestProperty("Content-type","aplication/x-www-form-urlencode");

System.out.print("Connect ");
http.connect();
http.setDoOutput(true);
http.setDoInput(true);

OutputStream outs = http.getOutputStream();
outs.write(PacketData);
outs.flush();

InputStream ins = http.getInputStream();
System.out.print("Response ");
data_count = ins.read(datain);

System.out.print("Disconnect ");
http.disconnect();

return true;

System.out.println("Done.");

} catch (MalformedURLException e) {
System.out.println("URL " + e.toString());
} catch (IOException e) {
System.out.println("IO " + e.toString());
}

return false;
}

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *