我想从https://www.google.com/finance/converter?a=1&from=USD&to=BDT获得转换后的费率,如果设备连接到wifi,一切都能正常工作。但是,如果我使用移动数据调用API,我只会获得部分响应。移动数据响应有限制吗?还是出于其他原因?
的问候。
private class GetConvertCurrency extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... strings) {
HttpHandler sh = new HttpHandler();
String data=null;
HttpURLConnection urlConnection1st = null;
HttpURLConnection urlConnection2nd = null;
HTTPUtil.disableConnectionReuseIfNecessary();
String responseStr;
StringBuffer buffer = new StringBuffer();
try {
url=strings[0];
URL urlToRequest = new URL(url);
Log.e("URl",urlToRequest.toString());
HttpURLConnection urlConnection = (HttpURLConnection) urlToRequest.openConnection();
try {
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(
urlConnection.getInputStream()));
System.out.println("urlConnection.getResponseCode() = " + urlConnection.getResponseCode());
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line).append("\n");
}
bufferedReader.close();
return stringBuilder.toString().trim();
} finally {
urlConnection.disconnect();
}
}
catch(Throwable t) {
t.printStackTrace();
}
return data;
}
@Override
protected void onPostExecute(String s) {
StringBuffer buffer = new StringBuffer();
String data = null;
if(s!=null){
Document doc = null;
doc = Jsoup.parse(s);
String title = doc.title();
buffer.append("Title: " + title + "rn");
Elements topicList = doc.select("span.bld");
buffer.append("Topic listrn");
for (Element topic : topicList) {
data = topic.text();
}
}
country_conversion_rate.put(countryData.getPrefix().trim(),s);
if(data!=null)upDateView(data);
else upDateViewWhenConversionRateNull();
}
}