HttpURLConnection not working over 3g only wifi
I have created a app that reads a json file across the internet. My app seems to work fine over wifi but when i use 3g it does not work for me on the orange network. I have a friend who tried it on a different network over 3g and it did work. I can browse the internet on 3g so i know i have a connection
I have added some debug code and found that its a IOException
file not found if that helps, but why can it find it on wifi?
My code is as follows:
String addr = "http://policeapi2.rkh.co.uk/api/crimes-street/all-crime?lat=" + strLat + "&lng=" + strLng;
URL url = new URL(addr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
String data = "user:password";
开发者_开发问答 String encoding = Base64.encodeToString(data.getBytes("US-ASCII"), Base64.DEFAULT);
conn.setRequestProperty ("Authorization", "Basic " + encoding);
conn.setRequestMethod("GET");
conn.connect();
InputStream in = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
StringBuilder stringBuffer = new StringBuilder();
while ((line = reader.readLine()) != null) {
stringBuffer.append(line);
}
精彩评论