wood burning stoves 2.0*
The moose likes Java Micro Edition and the fly likes Parameters GET after a connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Parameters GET after a connection" Watch "Parameters GET after a connection" New topic
Author

Parameters GET after a connection

Ould Nadif
Ranch Hand

Joined: Jan 21, 2004
Posts: 184
Hi all,

I would like send a connection to my server with 3 paramaters using httpConnection GET.

For example http://myserver.com/param1=1¶m2=2¶3=3

I know that : conn = ( HttpConnection )Connector.open "http://myserver.com/param1=1¶m2=2¶3=3") works fine.

My question is:

Is it possible to have the same result using the following :

First of all I send this connection
conn = ( HttpConnection )Connector.open "http://myserver.com).

If the connection works is OK I send this:

os = conn.openOutputStream();
os.write("param1=1¶m2=2¶3=3".getBytes());
os.flush();

Thanks you in advance

OULD NADIF


We are ones that build the world, thus build it well.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Yes, but I think you will want to look at the setRequestProperty(String key, String value) method. Remember that even though you are on J2ME, the methods that you need to set content, heard, etc information in your Request object is available.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ould Nadif
Ranch Hand

Joined: Jan 21, 2004
Posts: 184
Hi,

I couldn't recuperate the values of parameters side server.
The value worth null side server.
param1=null etc...
...
..
conn = ( HttpConnection )Connector.open( "http://myserver.com",Connector.READ_WRITE );
conn.setRequestMethod(HttpConnection.GET);
conn.setRequestProperty("param1","1");
conn.setRequestProperty("param2","2");
conn.setRequestProperty("param3","3");
...
....

Netherless, If I use http://http://myserver.com?param1=1¶m2=2¶m3=3
in the browser then I recuperated the value of param1, param2 etc.. side Servlet, therefore my servlet works fine.

I have doubts if setRequestProperty send the parametres of the connection.

Thank you for your help.

OULD
Eduardo Marques
Ranch Hand

Joined: Feb 19, 2005
Posts: 231
I think several things are being mixed up here:

- If you want to set a query string with GET you should specify it in the URL . For example:
HttpConnection c = (HttpConnection)Connector.open("http://host.com?a=1&b=2");

- To use the connection's ouput stream the request type has to be set to POST.
c.setRequestType(HttpConnection.POST);
OutputStream os = c.openOutputStream();
os.write(what_you_want);
os.close();

- setRequestProperty() methods sets information in the HTTP protocol request header - this is not very good to pass data parameters and may
be misunderstood by the HTTP server.

Also, depending on which method you use the interface at the other end is different.


Eduardo Marques
Get ready for your SCMAD certification at J2MECertificate.com - See what all the buzz is about ...
Ould Nadif
Ranch Hand

Joined: Jan 21, 2004
Posts: 184
Thank you for your reply.
I agree with you.Finally I replace GET by POST.I seems it works better.

Cheers

OULD
 
Consider Paul's rocket mass heater.
 
subject: Parameters GET after a connection
 
Similar Threads
Response from URL
Connection Pooling
doubt in creating connections..
A simple J2me Httpconnection not working - try for yourself
How to implement HTTP connection time out