を使用して投稿データでhttp://ws.audioscrobbler.com/2.0/に接続しようとするとHttpURLConnection
、(ランダムに)
EOFException
また
FileNotFoundException: http://ws.audioscrobbler.com/2.0/
Android 4.2.2 を実行している Nexus 4 で。
誰でも助けることができますか?
編集
4.3 にアップグレードしました: 同じ問題です。
public InputStream getData(String url_str, List<NameValuePair> postData) {
Map<String, Object> response = new HashMap<String, Object>();
InputStream is = null;
HttpURLConnection conn = null;
try {
URL url = new URL(url_str);
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(CONNECTION_TIMEOUT);
conn.setConnectTimeout(READ_TIMEOUT);
conn.setRequestMethod("POST");
conn.setDoInput(true);
if(postData != null){
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8"));
writer.write(getQuery(postData));
writer.close();
os.close();
}
// Starts the query
conn.connect();
// Get and return response
is = conn.getInputStream();
return is;
} catch (IOException e) {
// ...
} finally {
if(conn != null){
conn.disconnect();
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private String getQuery(List<NameValuePair> params) throws UnsupportedEncodingException
{
StringBuilder result = new StringBuilder();
boolean first = true;
for (NameValuePair pair : params)
{
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(pair.getName(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(pair.getValue(), "UTF-8"));
}
return result.toString();
}