POST parameters
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sascha_iseli
Posted On:   Monday, July 29, 2002 02:54 AM

Hi there. I have a big problem, i couldn't send with my midlet any parameters to a simple servlet. I read some articles about the problems with the flushing of the outputstream (->chunked encoding). I changed my Source code, but everytime, when i try to get my parameters from the servlet, they are always NULL! what should I do ?? I use the tomcat 4.0.4. Source Code MIDLet: .... HttpConnection c = null; InputStream is = null; OutputStream os = null; StringBuffer b = new StringBuffer(); String dat ="to=test1&subject=test2"; TextBox t = null; try { c = (HttpConnection)Connector.open(url);    More>>

Hi there.

I have a big problem, i couldn't send with my midlet any parameters to
a simple servlet. I read some articles about the problems with the flushing
of the outputstream (->chunked encoding). I changed my Source code,
but everytime, when i try to get my parameters from the servlet, they are
always NULL! what should I do ?? I use the tomcat 4.0.4.



Source Code MIDLet:


			....
			
HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
StringBuffer b = new StringBuffer();
String dat ="to=test1&subject=test2";
TextBox t = null;
try {
c = (HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("CONTENT-TYPE",
"application/x-www-form-encoded");
c.setRequestProperty("User-Agent", "Profile/MIDP-1.0
Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
c.setRequestProperty("Content-Length",
Integer.toString(dat.getBytes().length));

os = c.openOutputStream();
os.write(dat.getBytes());
//os.flush();
os.close();

is = c.openDataInputStream();
int ch;
while ((ch = is.read()) != -1) {
b.append((char) ch);
System.out.println((char)ch);
}
System.out.println("hier der komplette string1 "+b);
t = new TextBox("Confirmation", b.toString(), 1024, 0);
t.setCommandListener(this);
} finally {
if(is!= null) {
is.close();
}
if(os != null) {
os.close();
}
if(c != null) {
c.close();
}
}
display.setCurrent(t);
}


Source Code of the Servlet:


			

....
try
{
response.setContentType("text/plain");
Enumeration p = request.getParameterNames();
int loop=0;
while(p.hasMoreElements()){
num++;
String name=(String)p.nextElement();
System.out.println("Parametername ist "+num+" : "+name);

values = request.getParameterValues(name);
loop=0;
while(loop
System.out.println("Value "+values[loop]);
loop++;
}
}

String to = request.getParameter("to");
String subject = request.getParameter("subject");

System.out.println(" Werte sind : ");
System.out.println("to : "+to);
System.out.println("subject : "+subject);
System.out.println("msg : "+msg);
System.out.println("----------------------");

PrintWriter out = response.getWriter();

out.println("verbindung io...

..");
if(to==null){
System.out.println("Parameter are NULL");
}else{
System.out.println("alles gut : "+to+" "+subject+" "+msg);
}
....

thanks very much for your help regards Sascha

   <<Less

Re: POST parameters

Posted By:   Liam_Quinn  
Posted On:   Monday, July 29, 2002 09:27 AM

The Content-Type header set by your MIDlet is incorrect. The Content-Type should be "application/x-www-form-urlencoded".
About | Sitemap | Contact