HTTPRequest with Post Method

33 views
Skip to first unread message

mbmai...@gmail.com

unread,
Feb 10, 2014, 7:42:03 AM2/10/14
to codenameone...@googlegroups.com

Hi,
can you give me the Sample Code for an HTTP Request. I know I have to use the ConnectionRequest Class, I worked out the following code. But it is not completet:

       ConnectionRequest req = new ConnectionRequest();
        req.setPost(true);
        req.setHttpMethod("POST");
        req.setContentType("application/x-www-form-urlencoded");
       
        req.setUrl("http://s-software.com/authentication.json");
        Hashtable ht = new Hashtable();
        //populate the request object
        ht.put("name", "demo");
        ht.put("password", "demo");  
        req.getResponseData();    

The Parameters have to been read by a streamreader. Can somebody complete this code.
Waiting for your response.


Shai Almog

unread,
Feb 10, 2014, 12:47:02 PM2/10/14
to codenameone...@googlegroups.com, mbmai...@gmail.com
Hi,
you don't need req.setHttpMethod once you defined post.
How does the service accept the arguments? If its regular post arguments you can just do:
req.addArgument("name", "demo");

etc.

To send the request just invoke addToQueueAndWait() and then getResponseData() will return the byte data from the service.
Reply all
Reply to author
Forward
0 new messages