JAVA代码
使用JAVA实现Seafile创建资料库、上传文件、创建文件夹等的接口代码如下:
/**
* 测试服务状态
*
* @param client
* @return
*/
public String ping(OkHttpClient client) {
Request request = new Request.Builder()
.get()
.url(SERVICE_URL + "/api2/ping/")
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
return response.body().string();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 获取token
*
* @param client
* @param username 账号
* @param password 密码
* @return
*/
public String obtainAuthToken(OkHttpClient client, String username, String password) {
RequestBody body = new FormBody.Builder()
.add("username", username)
.add("password", password)
.build();
Request request = new Request.Builder()
.url(SERVICE_URL + "/api2/auth-token/")
.header("Content-Type", "application/x-www-form-urlencoded")
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
JSONObject jObj = parseJson(response.body().string());
return jObj.getString("token");
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
更多接口实现的具体代码详见:Seafile_WebApi;
此系列的其他文章
- Centos 7基于seafile搭建个人网盘服务端(mysql环境);
- Centos 7基于seafile离线搭建个人网盘服务端(mariadb环境);
- Seafile Java API接口实现示例;
- CentOS 7搭建seafile服务端(远程连接mysql数据库);
参考: