我在将数据传递给 Vuejspost方法时遇到问题。我正在使用 vue-resource 并且在文档中是:
this.$http.post('/someUrl', [body], [options]).then(successCallback, errorCallback);
Run Code Online (Sandbox Code Playgroud)
我想放置标题并且它可以正常工作(服务器读取标题正确):
this.$http.post(
'http://localhost:8081/login',
{
headers: {
'Accept': 'application/json'
}
});
Run Code Online (Sandbox Code Playgroud)
但是如果我尝试添加任何数据就会出错,例如我尝试过:
this.$http.post(
'http://localhost:8081/login',
{username: 'admin'},
{
headers: {
'Accept': 'application/json'
}
});
Run Code Online (Sandbox Code Playgroud)
或定义一些数据并放在那里,例如:
this.$http.post(
'http://localhost:8081/login',
this.data,
{
headers: {
'Accept': 'application/json'
}
});
Run Code Online (Sandbox Code Playgroud)
并且对于这两种解决方案,主体部分始终为空 - 使用以下方法检查请求中的主体数据:
body = req.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
Run Code Online (Sandbox Code Playgroud)
可能问题出在 vue.js 代码中,因为它工作正常,我从 Postman 发送任何请求。我该怎么办?
在列表适配器getview方法中使用sharedpreferences的最佳方法是什么?我必须使用来自sharedpreferences的一些值,但不知道如何获取它。我试过了:
pref = getApplicationContext().getSharedPreferences("pref", MODE_PRIVATE);
Run Code Online (Sandbox Code Playgroud)
它在活动中起作用,并且:
SharedPreferences pref = this.getActivity().getSharedPreferences("pref", Context.MODE_PRIVATE);
Run Code Online (Sandbox Code Playgroud)
可以分段工作,但都不能在listadapter中工作。
java android android-arrayadapter sharedpreferences android-studio