×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    36

    Http Request to Servlet on 6100

    I am trying to write an application which polls a servlet on a remote server for information.

    The problem is that the phone connects to the servlet (this is logged on the server) and the server makes a valid response. However the phone always displays the result to be "Cancel". Whatever text I get the servlet to return the MIDlet on the phone always displays this text. There is no place in either the servlet or the MIDlet code where this value could come from.

    Does anyone know what could be causing this?

    The code for the servlet and MIDlet follow.

    thx for any help.




    --SERVLET--
    public class TestServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

    PrintWriter out = response.getWriter();
    out.println("hello");

    }

    }

    --MIDLET--
    connection = (HttpConnection)Connector.open(s);
    os = connection.openOutputStream();
    os.write("hello".getBytes());
    os.flush();
    is = connection.openDataInputStream();

    int ch;
    while((ch = is.read()) != -1) {
    sb.append((char) ch);
    }
    System.out.println(sb.toString());
    --------------

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4
    Have you tried setting the content type of the content sent back
    from the midlet. I've seen several networks that have some sort
    of translation that occurs between the servlet and the handset
    unless you specifically specify a content type that you want it to
    'leave alone.'

    Try adding:

    PrintWriter out = response.getWriter();
    response.setContentType ("application/octet-stream");
    out.println("hello");

    or even specifying the length explicitly:

    OutputStream os = response.getOutputStream ();
    response.setContentType ("application/octet-stream");
    response.setContentLength (5);
    os.write ("hello");

    and let me know if that does the trick.

    --lee

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    36
    Thank you, that worked a treat.

    Thats 2 days of tearing my hair out and going around in circles that could've been avoided if i had posted here earlier.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×