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
Posts: 16
Registered: ‎05-03-2011
My Device: 98000
My Carrier: Student

Make an HTTP Connection to add file of client

I want to add some informations of client. Normally I have to use PUT method but I found that I platform blackberry don’t support HTTP PUT. 
(http://supportforums.blackberry.com/t5/Java-Development/HTTP-PUT-in-Blackberry/m-p/495269#M100027)

For this I tried to use POST method. I did this code but is not working.

 

public static void Addclient() throws IOException, JSONException {
		HttpConnection c = null;
		OutputStream os = null;
		int rc;

		try {
			
			String concatlog = idrecup + ":" + mprecup;
			String login = concatlog;
			
			byte[] encoded = Base64OutputStream.encode(login.getBytes(), 0,
					login.length(), false, false);
	
			c = (HttpConnection) Connector.open("http://teo.lis-contional.com:700/sap/map/lea/request/new/command/create?sap-client=7000;deviceside=t...");

			c.setRequestProperty("Authorization", "Basic "
					+ new String(encoded));
			rc = c.getResponseCode();		 

			 c.setRequestMethod(HttpConnection.POST);
	            c.setRequestProperty("NAME", "Pedro");
	            c.setRequestProperty("SURNAME", "Alanzo");
	            c.setRequestProperty("BIRTHDAY", "2001020400:36");

	            os = c.openOutputStream();
	            os.write("LIST games\n".getBytes());
	            os.flush();          
	            os.close();
	
		} catch (ClassCastException e) {
			throw new IllegalArgumentException("Not an HTTP URL");

		}
	} 

 

Im beginner and I don’t know what I will do. Can you give me please some links helpful to understand and succeed this task?

Thanks.

Developer
Posts: 146
Registered: ‎07-24-2008
My Device: none
My Carrier: none

Re: Make an HTTP Connection to add file of client

HI
you need to first set all the property and call the

rc = c.getResponseCode();
after os.flush().

It should work

Thanks
Ankit
Thanks & Regards,
Ankit Dubey
Module Lead Software Engineer, mLabs
Impetus InfoTech (India) Pvt. Ltd.
Contributor
Posts: 16
Registered: ‎05-03-2011
My Device: 98000
My Carrier: Student

Re: Make an HTTP Connection to add file of client

rc = c.getResponseCode();  is just to get back the code of connection (ex 200, 401 …) im my case I retrieve 200 so I can connect to webservice.

 

Normally my webservice has dealt request of PUTs method. Do you think that I have to change it in orther to deal POSTs methods?



Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Make an HTTP Connection to add file of client

Are you using 2 ids?

 

This looks like a remarkably similar question:

http://supportforums.blackberry.com/t5/Java-Development/Make-an-HTTP-Connection-to-add-file-of-clien...