Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
alexis1704
Posts: 29
Registered: ‎04-05-2010
My Carrier: NI
Accepted Solution

Rest response

Hi everybody!!

 

Can someone help me, how to make a http connection that is a restful webservice that recieve json file?

 

Thanks a lot...

Please use plain text.
Developer
DAquilina
Posts: 587
Registered: ‎01-19-2010
My Carrier: Rogers

Re: Rest response

Um... what?

 

If you're trying to call a web service, use JSR 172 or kSOAP2 (API). I can provide some snippets if you need them. If you're trying to make a POST request, try something like the following:

 

 

      //Open a connection to the website
      HttpConnection conn = (HttpConnection) Connector.open (IP + path + queryString);
      
      DataInputStream dataStream = conn.openDataInputStream ();

      byte [] buffer = new byte [dataStream.available ()];
      int length = dataStream.read (buffer);

 

 

I don't know what restful means...

 

Good luck,

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Please use plain text.
Contributor
alexis1704
Posts: 29
Registered: ‎04-05-2010
My Carrier: NI

Re: Rest response

Thanks a lot DAquilina It was very helpful for me, thanks a lot!!

Please use plain text.
Developer
DAquilina
Posts: 587
Registered: ‎01-19-2010
My Carrier: Rogers

Re: Rest response

Glad I could help :smileyhappy:

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Please use plain text.
Developer
filiussoft
Posts: 106
Registered: ‎06-18-2009

Re: Rest response

If you are working with a RESTful webservice, you can use the plain HTTP or HTTPS connection.  The API only has constants for post and get but you can pass UPDATE, DELETE, ... to setRequestMethod.

 

Take a look at the JavaDoc.  It has some example.  I dont have one on hand right now but I have used the HttpConnection to connect to a RESTful webservice.

 

You just have to put your reponse stream back into objects from JSON.  There is code at json.org for J2ME.

----
If this helped you, press the thumbs up button (on the far right - '+' thumb icon)
If this post solved the issue, click "Accept as Solution"
Please use plain text.
Contributor
alpachino
Posts: 22
Registered: ‎03-23-2011
My Carrier: Student

Re: Rest response

HI

 

 

I want to retrieve data from a server by REST

4 hours from now, I'm looking for one code sample of calling webservice from blackberry  with https but whitout succes. please there is anyone may help me. I want to  attract your attention that im beginner in developement java for blackberry 

I put the code that I have done but Im not sure if is good

 

thanks in advance

public class Dataretrieve {
	
	public String url=  " http://the link of my server";
	
	HttpsConnection openconn = (HttpsConnection) Connector.open (url);
    
    DataOutputStream dataStream = conn.openDataOutputStream ();
    
    

  
 


    
    
}

 

Please use plain text.