01-16-2013 05:49 AM
Good morning!
I'm trying get a string from url on server, but the application stop in StreamConnection. The code is:
public static String getPage(String url) {
String response = "";
try {
System.out.println("###########\nURL a transferir:\n"+url);
StreamConnection s = (StreamConnection)Connector.open(url,Connector.REA
System.out.println("###########\nStream Connection:");
InputStream input = s.openInputStream();
System.out.println("###########\nInput Stream:");
byte[] data = new byte[256];
int len = 0;
StringBuffer raw = new StringBuffer();
while( -1 != (len = input.read(data))) {
raw.append(new String(data, 0, len));
}
System.out.println(raw+"this is raw data");
response = raw.toString();
input.close();
s.close();
} catch(Exception e) {
System.out.println(e);
}
return response;
}
Cumps Diogo Pinto
01-16-2013 09:46 AM
Have you looked at htmlDemo. I think it does exactly this and it demonstrates how to execute networking off the Event Thread.
In addition, I recommend that you put network in the Search box and review any links you think might be useful. I would certainly review this one:
http://supportforums.blackberry.com/t5/Java-Develo
01-16-2013 11:31 AM
I've been experimenting with HTTPDemo but it happens to me the same thing the following message "java.io.InterruptedIOException: Local connection timed out after ~ 120000"
01-16-2013 12:21 PM
It woud have been useful to know that right from the start. Please give us as much informaiton as you can when you ask a quesiton.
The timeout means you can't connect to get the information. You need to understand networking better. Start here:
http://supportforums.blackberry.com/t5/Java-Develo
Review this:
and then look at the documentation for ConnectionFactory.
01-17-2013 11:55 AM
Well I was a bit the same
.
In Iphone and android I did it without much problem and very easy!
What I want is just to get information php a file on the server, as simple as that!
It can not be that complicated to say but I do not need anything. Have a suggestion to make it so?
01-17-2013 01:22 PM
I've answered a very similar quesiton here:
http://supportforums.blackberry.com/t5/Java-Develo
Please check that out and see if it helps.
01-18-2013 05:21 AM
I've been watching this post and in my case I do not get an xml file but the result giving the url and get it to a string. The url is constructed so "http://linkserver/appname/file.php?param=1" the server returns a text that I want to fetch and analyze later.
The way that this post has not got anything to get it
.
01-18-2013 07:32 AM - edited 01-18-2013 07:33 AM
OK, I am not clear that you have understood what I was saying in this post:
Let me try to repeat it a different way.
The BlackBerry has a variety of different connection paths it can use to connect from the BlackBerry to the Server. You can tell the BlackBerry which connection path you want it to use by specifying the connection string, which is the suffix you add to the URL. On a Simulator, if you tell it nothing, it will try to connect via the MDS connection, which will only work if you have the MDS Simulator running. If you don't want to have the MDS Simulator running, then specify
";deviceside=true"
as a suffix to your URL.
I recommend that if you are testing on the Simulator, then add ";deviceside=true" to your URL, then make the connection. Try this with htmlDemo and let us know what happens.
01-18-2013 07:55 AM
In the simulator works, but how do the mobile phone? both can be connected by wifi or 3G?
01-18-2013 08:43 AM
OK, then you just need to choose the correct connection string for the phone. But I recommend that you do not do it that. Instead look at using ConnectionFactory. The documentation for this is not bad and there are many other Threads on this forum that discuss ConnectionFactory that should help.
Sorry this is not a trivial exercise on a BlackBerry.