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
Highlighted
Contributor
Posts: 35
Registered: ‎02-05-2012
My Device: Playbook
My Carrier: T-Mobile
Accepted Solution

HTTP data truncated

I am writing an app which accesses a web site and reformats the data for Blackberry. All seems fine via wi-fi, but when using mobile network the data is truncated. Saving the html in notepad shows that only around 6k is being sent. Does anyone know why this should be and how to resolve it? Thanks in anticipation.

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

Re: HTTP data truncated

Data being sent is truncated, or response received is truncated. 

 

I presume data received.  If so, do you have the Server logs to prove that it sent it all?   Can we see the code that does the receive? 

 

Which communication method (Carrier TCP, WAP, BES or BIS-B) are you using?

Contributor
Posts: 35
Registered: ‎02-05-2012
My Device: Playbook
My Carrier: T-Mobile

Re: HTTP data truncated

Thanks for replying. Apologies, data received is being truncated. Not sure how I'd access ther server logs.

 

Blackberry is all very new to me, but as I'm using a personal phone with a prepaid sim without declaring any APN that it must be BIS-B? 

 

This is the code:

 

try {

HttpConnection c = (HttpConnection) Connector.open(_url, Connector.READ_WRITE);


if (_post != "") {
OutputStream os = c.openOutputStream();
os.write(post.getBytes("UTF-8"));
os.flush();
os.close();
};

InputStream in = c.openInputStream();
StringBuffer myStringBuffer = new StringBuffer();
int b;

while ((b = in.read()) != -1) {

myStringBuffer.append((char)b);

}

_pageContent=myStringBuffer.toString();
in.close();

}
catch(Throwable e) {

_pageContent = "error";
System.out.println("*****Web error " + e);

}


return _pageContent;

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: HTTP data truncated

For one thing, you should be getting the response code before trying to process the data.

 

See HTTPConnection,.getResponseCode()

 

 

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

Re: HTTP data truncated

RexDoug makes a very good point.  I would also check the content of the data.  It is possible that you are getting some carrier redirect page rather than the page you think you are getting.

 

Since you do not specify anything, the phone will be using the default connection method.  Since it is not a corporate phone, it will almost certainly be using WAP, which means it goes through a carrier gateway.  You could be getting something like a 'redirect' page asking you to sign in or to set the parental controls, as sent by your carrier. 

Contributor
Posts: 35
Registered: ‎02-05-2012
My Device: Playbook
My Carrier: T-Mobile

Re: HTTP data truncated

Thanks for the replies guys, useful to know about the response code.

 

Peter, I have examined the data returned in Eclipse and it is the data I would expect but truncated part way through.

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

Re: HTTP data truncated

OK.

 

Can I ask you to put the following code:

-----------------------------------------------------------------------

if ( c.getResponseCode() != 200 ) {

throw new RuntimeEception("Unexpected retun code: " + c.getResponseCode());

}

int len = (int) c.getLength();

System.out.println("Server bytes sent: " + len);

InputStream in = c.openInputStream();
byte [] data = IOUtiities.streamToBytes(in);

System.out.println("Server bytes received: " + data.length);

try {

_pageContent = new String(data, "UTF-8");

System.out.println("Sercharacters received: " + _pageContent.length());

}catch (Exception e) {

}
in.close();

-----------------------------------------------------------------------

 

in place of:

 

-----------------------------------------------------------------------

InputStream in = c.openInputStream();
StringBuffer myStringBuffer = new StringBuffer();
int b;

while ((b = in.read()) != -1) {

myStringBuffer.append((char)b);

}

_pageContent=myStringBuffer.toString();
in.close();

-----------------------------------------------------------------------

 

Check to see if the full data is returned in data

Contributor
Posts: 35
Registered: ‎02-05-2012
My Device: Playbook
My Carrier: T-Mobile

Re: HTTP data truncated

[ Edited ]

Apologies for not replying sooner Peter. I really appreciate your help. Data is now returned fully via wifi and network...to a point! Seems totally bizarre to me, but my app firstly requires the user to log in, then requests some data for display, after which the user can select a search option which requests more data for display on the search screen. This all works perfectly over wifi, but over the network the log in and initial request work, but the search request returns nothing (response code is 200). I can't think of any reason why it should be different, totally stumped!