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
New Developer
Posts: 27
Registered: ‎08-26-2008
My Device: Not Specified

HTTP POST Problem

I have done a test, find there has a problem in Http connnection using POST methods: the flush() only could be used once!

 

some code below:

 

1. use flush() only once. My program works right.

 

String url = ".....;deviceside=true";
String postStr1 = "xxx=1";
String postStr2 = "&yyy=2";

httpConnection = (HttpConnection) Connector.open(url);
httpConnection.setRequestMethod(HttpConnection.POST);

output = httpConnection.openOutputStream();
output.write(postStr1.getBytes());
output.write(postStr2.getBytes());

output.flush();
output.close();

 

2. use flush() twice , there has a exception

 

String url = ".....;deviceside=true";
String postStr1 = "xxx=1";
String postStr2 = "&yyy=2";

httpConnection = (HttpConnection) Connector.open(url);
httpConnection.setRequestMethod(HttpConnection.POST);

output = httpConnection.openOutputStream();
output.write(postStr1.getBytes());
output.flush();

output.write(postStr2.getBytes());

output.flush();
output.close();

 

 

I trace it and find after first flush(), when run to output.write(postStr2.getBytes()); there have the Exception: java.lang.RuntimeExceptionSmiley Frustratedtream closed

 

which means after flush(), the stream is closed!.

 

I know in standard Java, there has no such limit, I can use flush() many times. I don't know if this is BUG?

 

 

 

New Developer
Posts: 27
Registered: ‎08-26-2008
My Device: Not Specified

Re: HTTP POST Problem

I test it by many url, flush() method can only use once. else there has exception.

 

I also test it using standard java, i can use flush() many times without any exceptions.

New Developer
Posts: 27
Registered: ‎08-26-2008
My Device: Not Specified

Re: HTTP POST Problem

I thought maybe there have some  BUGs in OutputStream's flush(), So I test OutputStream alone, found I can use flush() many times.

Here are some code:

 

OutputStream outputStream = fileConnection.openOutputStream();
String outStr = "ABC";
outputStream.write(outStr.getBytes());
outputStream.flush();
outputStream.write(outStr.getBytes());
outputStream.flush();
outputStream.close();

 

I think it must has some BUGs in HTTP POST flush().

Highlighted
New Developer
Posts: 27
Registered: ‎08-26-2008
My Device: Not Specified

Re: HTTP POST Problem

MSohm, could you confirm this problem? Thx
BlackBerry Development Advisor
Posts: 15,211
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: HTTP POST Problem

I have confirmed that this is the expected behaviour due to the fact that the BlackBerry only supports HTTP 1.0, not HTTP 1.1.  Therefore HTTP connections should only call flush once.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 13
Registered: ‎10-25-2008
My Device: Not Specified

Re: HTTP POST Problem

Hi All ,

 

Is it possible to do Http post to an Asp page.

I am able to post text  data to Asp page but whole file is not getting received at server end.

Please help me.

or Should I switch to socket communication with a desktop server for posting a file.

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: HTTP POST Problem

I'm not sure I understand the issue with flush. The general contract for flush is to push out whatever you have.

The changes the time sequencing of data going to the other end and in cases like with console IO it can be

called often. For sure, with pipelining you want to push data out often but I don't see how this would be

relevant here- you can force IO of small amounts of data and the server accumulates these until it gets

whatever it needs to respond like a blank line for a get request.

 

Flush doesn't close a connection AFAIK and doesn't change the data. The server can't make many assumptions

about the arrival time or packetization of the request.