The code worked perfectly. Thanks for the help.

On Sep 27, 2:46 pm, Jeffrey Blattman <[email protected]>
wrote:
> no, there's a default read timeout. the only thing i noticed wrong was
> that you were writing to URL itself to the stream.
>
> On 9/27/09 11:42 AM, HTN wrote:
>
>
>
>
>
> > Seems like I was on the right track as I had url.openconnection. Is
> > the ReadTimout portion what I was doing wrong?
>
> > I'll try the code out when I get back home tomorrow. Thanks for the
> > help.
>
> > On Sep 27, 2:21 pm, Jeffrey Blattman<[email protected]>
> > wrote:
>
> >> nah. first, he said that the endpoint wants GET params, and you are
> >> opening with POST method below. you don't need to write data to the
> >> stream. the data is passed to the endpoint as GET params.
>
> >> if you just want to pass the get params, it's enough to just call
> >> openConnection(). depending on how the endpoint returns a response, you
> >> can check the response code with getResponseCode(), or you can read a
> >> data response (XML, JSON, etc) by calling getInputStream(). here's the
> >> simplest case,
>
> >>               URL url = new URL(urlString);
> >>               HttpURLConnection uc = (HttpURLConnection)
> >> url.openConnection();
> >>               uc.setReadTimeout(30 * 1000); // 30 seconds
>
> >>               if (uc.getResponseCode() != 200) {
> >>                   //TODO: handle error and return
> >>               }
>
> >>               reader = new BufferedReader(new
> >> InputStreamReader(uc.getInputStream(), "ISO-8859-1"), 8192);
> >>               while ((line = reader.readLine()) != null) {
> >>                   result.append(line);
> >>                   result.append('\n');
> >>               }
>
> >>               // result data is in "result"
>
> >> On 9/27/09 11:07 AM, Alok Kulkarni wrote:
>
> >>> 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]
> >>> <mailto:[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&n...
> >>>      
> >>> <http://192.168.0.12/output_format=xml&DeviceNum=13&action=SetTarget&n...>
>
> >>>      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]
> >>>      <mailto:[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
-~----------~----~----~----~------~----~------~--~---

Reply via email to