I am trying to fetch some web services from blackberry code. Heres the code I am using
public void execute(int method)
{
HttpConnection connection = null;
try
{
switch(method)
{
case GET:
{
String combinedParams = "";
if(!params.isEmpty())
{
combinedParams += "?";
for(int i=0;i<params.size();i++)
{
String[] nameValue = SplitString.split(params.elementAt(i).toString(), ",");
String paramString = nameValue[0] + "=" + nameValue[1];
if(combinedParams.length() > 1)
{
combinedParams += "&" + paramString;
}
else
{
combinedParams += paramString;
}
}
}
if(combinedParams.equals(""))
{
System.err.println("URL = "+url);
connection = (HttpConnection)Connector.open(url);
}
else
{
connection = (HttpConnection)Connector.open(url+combinedParams);
}
connection.setRequestMethod(HttpConnection.GET);
executeRequest(connection);
break;
}
case POST:
{
connection = (HttpConnection)Connector.open(url);
connection.setRequestMethod(HttpConnection.POST);
for(int i=0;i<headers.size();i++)
{
String[] nameValue = SplitString.split(params.elementAt(i).toString(), ",");
connection.setRequestProperty(nameValue[0], nameValue[1]);
}
if(getData()!= null)
{
OutputStream os = connection.openOutputStream();
os.write(getData().toString().getBytes());
os.flush();
}
executeRequest(connection);
break;
}
}
}
catch(Exception e)
{
System.err.println(e.getMessage());
e.printStackTrace();
}
}
As soon as I run this line
connection = (HttpConnection)Connector.open(url);
I am getting the error Required radio is not active
I dont have any sim card in the device but I am connected to a wifi and I can access other web pages from the browser.
What could be the possible reason for this error?
I have tried this link and the RadioInfo.getState() is Off in my case.
Thanks
From the docs on Connector:
Wi-Fi Support
Wi-Fi connection can be established by setting the interface parameter. This only works with direct TCP/UDP connections.
interface: If the
interface=wifi
parameter is appended to the end of the URI string value, a Wi-Fi socket connection is opened.
What this means is that you'll have to detect if the radio is off, and if it is you can attempt to use Wi-Fi by adding interface=wifi
to the URL. A proper URL would be: http://www.google.com;interface=wifi