我需要转换这个miniflux cURL命令:
curl \
-u "demo:swB3/nSo1CB1X2F" \
-d '{"jsonrpc": "2.0", "method": "feed.list", "id": 1}' \
https://demo.miniflux.net/jsonrpc.php
成为可用的java(android)代码,用于我的android应用程序。这是我的代码:
public static void post() {
try {
Log log = null;
String url = "https://demo.miniflux.net/jsonrpc.php ";
URL obj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
conn.setRequestMethod("POST");
String userpass = "demo" + ":" + "swB3/nSo1CB1X2F";
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes("UTF-8"));
conn.setRequestProperty ("Authorization", basicAuth);
String data = "{\"jsonrpc\": \"2.0\", \"method\": \"feed.list\", \"id\": 1}";
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream());
out.write(data);
out.close();
new InputStreamReader(conn.getInputStream());*/
} catch (Exception e) {
Log log1 = null;
log1.v("Exception>>>>>>","Exception Thrown O_O");
}
}
此代码抛出异常。关于miniflux卷曲命令的文档可以在这里找到:https://miniflux.net/documentation/json-rpc-api我做错了什么?感谢。