HTTP POST Help

Discussion in 'Android Hacks and Help' started by jsg7377, Dec 19, 2009.

  1. jsg7377

    jsg7377 New Member

    Joined:
    Dec 9, 2009
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Rochester, NY
    Ratings:
    +0
    Background:
    I have rigged up a remote start system for my Droid using a WebRelay. I am currently hosting a web server with a small webpage that I access from my Droid. This webpage sends the Lock, Unlock, Trunk, and Start command to the WebRelay in my car via a WWAN connection.

    Objective:

    I am looking to eliminate the hosted web server, and create a simple application that will just send the commands to the WebRelay when the corresponding onscreen button is pressed.

    Problem:
    I am hardware oriented and have no Java experience. I was hoping someone could help me with the syntax and point me in the right direction.

    Accomplishments:
    I have not gotten very far, but I have Eclipse Java EE IDE up and running, with the Android SDK and with my Droid as a debug device.

    Commands :
    I need to only send 4 commands, each to their respective feature (lock, unlock, trunk, start):


    Lock: "htttp://192.168.1.2/state.xml?relay1State=1"
    Unlock: "http://192.168.1.2/state.xml?relay2State=1"
    Trunk: "http://192.168.1.2/state.xml?relay3State=1"
    Start: "http://192.168.1.2/state.xml?relay4State=1"


    Thoughts:
    I am assuming I need to use some sort of HTTP POST method. I did some digging around in the plugins directory of eclipse and noticed there is an apache.commons with HttpClient features. I was hoping this would work to send POST commands in Java.

    Concerns:
    From what I have read there seem to be issues regarding the API (3.x vs. 4.0). This would obviously seem to cause a problem if the eclipse compiler is using a different version. Just something to think about...


    Disclaimer:
    If I am way off base, I'm sorry-- I have never looked at a Java program before yesterday. If this is harder than just creating a simple snippet for each command, I apologize -- please just let me know.

    Thanks in advance!!!
     
    Last edited: Dec 19, 2009
  2. Rizza

    Rizza New Member

    Joined:
    Dec 24, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    To send commands to a web address its really rather simple using http post comands, since they are just query string variables, you can do it in two lines..

    //define your URL
    URL myURL = new URL("htttp://192.168.1.2/state.xml?relay1State=1");
    //open a connection to the url
    URLConnection uCon = myURL.openConnection();

    There you go, you sent the commands to the server, thats it. Now if you want to get the response back, you'll need some more code, and i'll be glad to help with that, but hopefully this can get you started. Also dont forget to import the following in order to use the URL and URLConnection objects...

    mport java.net.URL;
    import java.net.URLConnection;

    Again, if you need more help, just email me at briridsdale--DOT--gmail.com (remove the --DOT-- and replace with @. I'll be happy to help walk you through building the app, and the actiivty, and layouts you'll need. Im interested in hearing more about your project.

    Rizza
     
Search tags for this page
http post url for verizon
,
http post verizon
,

htttp://192.168.1.2

,
htttp:/192.168.1.2
,
motorola droid 192.168.1.2