This works
URL url = new URL(serverURL);
// open the conncetion
HttpURLConnection connection =
(HttpURLConnection)url.openConnection();
// Let the run-time system (RTS) know that we want input.
connection.setDoInput(true);
// Let the RTS know that we want to do output
connection.setDoOutput(true);
// No caching, we want the real thing
connection.setUseCaches(false);
// set the content type property
connection.setRequestProperty("Content-type",strContenttype);
// set request method
connection.setRequestMethod("POST");
// create the post body to send
String content = credDevPair.toString();
Log.i("Request ====....... ",content);
DataOutputStream printout = new DataOutputStream (
connection.getOutputStream () );
// send the data
printout.writeBytes(content);
printout.flush();
printout.close();
On Sun, Sep 27, 2009 at 11:25 PM, HTN <[email protected]> wrote:
>
> It's through GET parameters. I can type in the following command in a
> browser's URL box and it works:
>
> http://192.168.0.12/output_format=xml&DeviceNum=13&action=SetTarget&newTargetValue=1
>
> I'm used to sending commands through TCP sockets so I'm sure what's
> the best way to send a URL command. I'm guessing the "opening" a URL
> part isn't adequate.
>
> On Sep 26, 8:49 pm, Jeffrey Blattman <[email protected]>
> wrote:
> > you are opening a URL, then writing that URL to the stream you open at
> > the URL. that's probably not what you wanted. what's the URL, and what
> > is the "command" you are trying to pass? how does the endpoint accept
> > the command? by reading POST data? through GET parameters?
> >
> > On 9/25/09 7:31 PM, HTN wrote:
> >
> >
> >
> >
> >
> > > I'm developing a remote app that sends commands via http. Normally I
> > > type in a link in a browser and the command will work. With Android, I
> > > would like it to work with a press of a button. I tried the following
> > > code and it didn’t work:
> >
> > > URL url = new URL(urlString);
> >
> > > URLConnection connection = url.openConnection();
> > > connection.setDoOutput(true);
> >
> > > OutputStreamWriter out = new OutputStreamWriter
> > > (connection.getOutputStream());
> > > out.write(urlString);
> > > out.close();
> >
> > > "urlstring" is the http command link.
> >
> > > Any ideas? Am I on the wrong track? I'm confused because technically I
> > > don't need to write anything to the link. I would think it would work
> > > if I just open the connection.
> >
> > > Thanks.
> >
> > --
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---