• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parameters GET after a connection

 
Ould Nadif
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ould Nadif
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ould Nadif
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply.
I agree with you.Finally I replace GET by POST.I seems it works better.

Cheers

OULD
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic