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
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

Your connection code looks OK, so I guess suspicion now falls on the POST parameters. 

 

Can you do some debugging on the Server to determine that it is receiving the request as a POST and receiving the parameters correctly? 

 

Also have you dumped out the bytes you are sending to make sure that they are correct?  To do this you will either have to print the bytes in hex or try something like this:

String postString = new String(mParams, "UTF-8);

and dump our postString.

Developer
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

peter I checked paramString while sending to connection class and before writing to connection's outputstream and found both to be same and correct .

 

when i checked connection.getUrl() method i found it to be http://www.myserver.com/services/login?;interface=wifi

 

which means my server would have been receiving request url to be http://www.myserver.com/services/login?;interface=wifi  instead of http://www.myserver.com/services/login? and parameters would have been written after this url if I am thinking right

 

It  means to handle my url at server as http://www.myserver.com/services/login?;interface=wifi  instead of http://www.myserver.com/services/login? or  at server side the url hit as http://www.myserver.com/services/login? this only (no handling required).

 


I am new to BB Java development .

Always Success
Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

;interface=wifi is an internal connection handle used by the bb framework, it will not be used outside of the device.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

[ Edited ]

Ok Simon

 

It means there could be some error while writing  parameters byte[] to connection's outputstream . Is it possible and if its possible how could we detect it  ? Just before writing I did checked  parameters and found them to be correct.

 

Can we detect complete url after the parameters are written to outputstream like in Android we can using HttpPost class

HttpPost p;

p.getEntity().getContent();  // returns inpustream which can in turn gives string rep of complete URL.

 

it gives url like :

http://www.myserver.com/services/login?username=mfsi&password=mfsi

 

 

 

 

 

 

 

 

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

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

That looks like a GET request to me.

 

Can print out the URL you are using and the post parameters you are using and tell us exactly what they are before you issue the request?

 

Have you managed to do any analysis at the Server end?

Regular Contributor
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

hii

 

i faced that problem when covert image into byte and try to send directly that byte to server

 

so i resolve by its using base64 encreaption

 

and i think its cause there some symbol in byte code so  may be...

 

 

Developer
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

peter don't mistake about what i said in context with Android. Please forget about it (and in that case its a Post request).

 

and just before issue the request :

 

URL : http://www.myserver.com/services/login?

Params(String from byte[]) : username=mfsi&password=mfsi

 

just wanted to know if there is any possibility of error while writing to outputstream

 

 

 

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

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

[ Edited ]

A URL with a "?" is to be an good indication of a URL you would use to do a GET.  The ? separates the URL from the query values.

 

Have a look at this page for more:

http://en.wikipedia.org/wiki/Query_string

 

I thought the POST was sent in the body of the request, so you will see it in the stream after the http headers.  In the output you showed us previously, the parameters came immediately after the URL.

 

More on POST here:

http://en.wikipedia.org/wiki/POST_(HTTP)

 

So I'm still not convinced that you are sending the request in the correct way.  If you can get your Server end person to look at what you are sending and how the Server is interpreting it, you will get to the bottom of this quicker.

 

Edit: Thanks for the input hitesh171285, but I am sure that this problem is different.   

 

Edit2:  I do not think there is a problem with your output of the POST bytes. 

Developer
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

Yes peter whatever you are saying is right .

 


peter_strange wrote:

 In the output you showed us previously, the parameters came immediately after the URL.


but whatever url I shown u was from my Android implementation and by writing it I only meant to know if anything like that is possible in android. 

 

Yes as u said I need to check also from server end what url and params are they receiving.

Thanks  peter , simon and hitesh

Always Success
Highlighted
Contributor
Posts: 10
Registered: ‎09-15-2012
My Device: Curve 9360
My Carrier: Vodafone

Re: Http Post Method is Not Working in simulator (SDK 7.0) and not in device with BB 5.0

Hi all,

 

Thanks to all of you.

 

I used MFSI's modified code of ConnectionThread class and its working at my end.

 

Thanks again 




*****************************************************************************

Why do we fall ? So we might learn to pick ourselves up.