我有一个适用于Android 2.x和3.x的Android应用程序,但在Android 4.x上运行时会失败.
问题出在这部分代码中:
URL url = new URL("http://blahblah.blah/somedata.xml");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
Run Code Online (Sandbox Code Playgroud)
当应用程序在Android 4.x上运行时,getInputStream()调用会产生一个FileNotFoundException.当在早期版本的Android上运行相同的二进制文件时,它会成功.URL也适用于Web浏览器和curl.
显然HttpURLConnection,ICS中有些变化.有没有人知道发生了什么变化,和/或修复可能是什么?
我正在尝试从Yahoo!检索市场数据 金融和剧本多年来一直运作良好,但最近,它停止显示道琼斯数据.这是URL:
http://download.finance.yahoo.com/d/quotes.csv?s=^DJI,^IXIC,^GSPC,^TNX&f=snl1d1t1c1ohg
该URL应返回以下数据:
它实际上没有为我返回CSV,我已经尝试了我能想到的一切,但无济于事,我没有看到任何人在网上遇到同样的问题.
任何想法,是否有任何人有同样的问题?
谢谢.
我发现这个问题的答案非常有用,但我想获得过去日期的汇率,而不仅仅是今天的汇率.我正在编写一个iPhone应用程序,它使用汇率来计算不同国家/地区的销售额.
以上是上述答案的例子,以获得今天英镑兑换欧元的汇率:http://download.finance.yahoo.com/d/quotes.csv? s = GBPEUR = X&f = sl1d1t1ba&e = .csv
有谁知道如何在其他任何日期执行此操作?谢谢!
我的Galaxy Nexus今天到了,我做的第一件事就是将我的应用程序加载到它上面,这样我就可以向朋友们展示它了.其部分功能涉及从Google阅读器导入RSS源.但是,在尝试这个时,我得到405方法不允许错误.
这个问题是Ice Cream Sandwich特有的.我附上的代码在Gingerbread和Honeycomb上运行良好.当GET请求神奇地变成POST请求时,我已经将错误追溯到建立连接的那一刻.
/**
* Get the authentication token from Google
* @param auth The Auth Key generated in getAuth()
* @return The authentication token
*/
private String getToken(String auth) {
final String tokenAddress = "https://www.google.com/reader/api/0/token";
String response = "";
URL tokenUrl;
try {
tokenUrl = new URL(tokenAddress);
HttpURLConnection connection = (HttpURLConnection) tokenUrl.openConnection();
connection.setRequestMethod("GET");
connection.addRequestProperty("Authorization", "GoogleLogin auth=" + auth);
connection.setRequestProperty("Content-Type","application/x-www-form-urlendcoded");
connection.setUseCaches(false);
connection.setDoOutput(true);
Log.d(TAG, "Initial method: " + connection.getRequestMethod()); // Still GET at this point
try {
connection.connect();
Log.d(TAG, …Run Code Online (Sandbox Code Playgroud) 我正在尝试为Android开发一个简单的外汇应用程序.首先,我需要获得过去一年的货币汇率.
任何人都可以建议我怎么做?我查看了Google financh API,但无法找到如何检索汇率.任何建议表示赞赏.
谢谢.