Reputation: 127
I am trying to send information to my company's server. Basically when I enter a URL pointing to it and connect to it in a browser, it takes parameters contained in the URL and puts them in a database. Again when done in a browser, it works. However, I would like to be able to send this information every time an event of importance (like scanning a qr code in our app) happens, and I want it to be done in the background (without the user knowing.)
We have tried ConnectionFactory, HTTPRequests etc etc, nothing has worked for us so far.
I am sure there is a simple way to go about this.
Can anyone provide us with the few elusive lines of code to help us do what we want to do??
Thanks alot!
Edit:
Okay here is some code we tried using (one of many code snippets) but it did not work:
public class ConnectionThread extends Thread{
String URL;
public ConnectionThread(String URL) {
this.URL = URL;
}
public void run() {
ServerCalls sc = new ServerCalls(); // This is for generating the URL
ConnectionFactory connFact = new ConnectionFactory();
ConnectionDescriptor connDesc;
connDesc = connFact.getConnection(sc.fillParameters(URL));
if (connDesc != null)
{
HttpConnection httpConn;
httpConn = (HttpConnection)connDesc.getConnection();
}
}
}
and we call new ConnectionThread(barcode).start()
when we need it to send the info to the server.
Upvotes: 0
Views: 1611
Reputation: 4942
For opening the url you can use
javax.microedition.io.HttpConnection
Package.
And here is the code how to go about that....
HttpConnection connection=(HttpConnection) Connector.open(your url+";deviceside=true");
if(connection.getResponseCode()==HttpConnection.HTTP_OK) {
write your code, Which you want to get from url or any thing you want
}else{
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.inform("connection error");
}
});
}
This may help you :)
Upvotes: 1