You Are Here:

Community: Developer Discussion Boards

#1 Old Http Request to Servlet on 6100 - 2003-04-11, 18:21

Join Date: Mar 2003
Posts: 36
cs8st
Offline
Registered User
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());
--------------
Reply With Quote

#2 Old 2003-04-12, 04:25

Join Date: Mar 2003
Posts: 4
arfff
Offline
Registered User
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
Reply With Quote

#3 Old 2003-04-14, 10:36

Join Date: Mar 2003
Posts: 36
cs8st
Offline
Registered User
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. :)
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia