• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Parameters GET after a connection

 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Arthur, where are your pants? Check under this tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic