04-25-2012 08:22 AM
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.
Solved! Go to Solution.
04-25-2012 09:28 AM
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?
04-25-2012 09:51 AM
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;
04-25-2012 11:36 AM
For one thing, you should be getting the response code before trying to process the data.
See HTTPConnection,.getResponseCode()
04-25-2012 12:30 PM
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.
04-25-2012 12:55 PM
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.
04-25-2012 01:30 PM
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
04-28-2012 08:39 AM - edited 04-28-2012 08:42 AM
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!