在我的应用程序中,我试图向我的服务器发出 HTTPS POST 请求。但是,我一直收到 SSLHandshakeException - 链验证失败。我尝试使用 POSTMAN 发送请求,但收到了服务器的响应。当我尝试从应用程序发送请求时,什么可能导致此错误?
这是我尝试发送发布请求的代码片段:
public static JSONObject getDataLibConfiguration(Context context) throws HttpRequestException {
int statusCode = 0;
JSONObject commonInformation;
HttpsURLConnection connection = null;
try {
commonInformation = ConfigurationProcessor.getCommonInformation(context);
if (commonInformation == null) {
return null;
}
URL url = new URL(BuildConfig.SERVER_CONFIG_URL);
if (BuildConfig.DEBUG) {
LogUtils.d(TAG, "url = " + url.getPath());
}
connection = getHttpsConnection(url);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setRequestProperty("Content-Encoding", "gzip");
byte[] gzipped = HttpUtils.gzip(commonInformation.toString());
cos = new CountingOutputStream(connection.getOutputStream()); //<-- This is where I …
Run Code Online (Sandbox Code Playgroud) 我是asp.net的新手我最近遇到过这个例外:
System.InvalidOperationException
例外的细节说:
尚未为此应用程序或请求配置会话.
以下是它发生的代码段:
[HttpPost]
public object Post([FromBody]loginCredentials value)
{
if (value.username.Equals("Admin")
&&
value.password.Equals("admin"))
{
HttpContext.Session.Set("userLogin", System.Text.UTF8Encoding.UTF8.GetBytes(value.username)); //This the line that throws the exception.
return new
{
account = new
{
email = value.username
}
};
}
throw new UnauthorizedAccessException("invalid credentials");
}
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会发生这种错误或者这个错误究竟意味着什么.有人可以解释可能导致这种情况的原因吗?
我正在学习如何使用 Mongoose,但有一些我不明白的地方 - 如何连接到集群中的特定数据库和集合?
我有 5 个不同的数据库,每个数据库都有几个不同的集合
当我使用纯 Mongo 客户端时 - 正如官方文档中显示的那样,我像这样连接:
const MongoClient = require('mongodb').MongoClient;
const uri = process.env.mongo_connection_string;
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
const collection = client.db("database_name").collection("collection_name");
// Do some work here in the selected database and the selected collection
client.close();
});
Run Code Online (Sandbox Code Playgroud)
现在想用Mongoose来练习。所以在我的 app.js 中建立连接我这样做:
mongoose.connect(process.env.mongo_connection_string , {useNewUrlParser: true})
.then( () => console.log("Connection established"))
.catch(err => console.log(err))
Run Code Online (Sandbox Code Playgroud)
然后,我为要存储在数据库中的对象之一创建了一个架构。
const mongoose = require('mongoose')
const UserSchema = new mongoose.Schema({
name: {
type: String, …
Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个我似乎无法解决的错误。我axios
与 一起使用TypeScript
。这是我尝试做的代码示例:
export const fetchTransactions = (PageNum: number, PageSize: number, Context_id: number) => new Promise<Transaction[]> (async (resolve, reject) => {
try
{
const response = await axios.post<AxiosResponse<Transaction[]>>(FETCH_TRANSACTIONS_URL, {PageNum, PageSize, Context_id})
const {transactions} = response.data
resolve(transactions)
}
catch (error) {
reject(error.response);
}
})
Run Code Online (Sandbox Code Playgroud)
现在我得到的错误如下const {transactions} = response.data
:
我怎样才能消除这个错误?正确的响应类型应该是什么?
我有以下代码片段:
public static String getAppVersion(Context context) {
String versionName = null;
try {
versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; //This is the problematic line
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return versionName;
}
Run Code Online (Sandbox Code Playgroud)
现在,根据 Crashlytics 的说法,应用程序崩溃时出现了以下异常:
Caused by android.os.DeadObjectException
com.tawkon.data.lib.util.ParameterUtils.getAppVersion
android.os.BinderProxy.transactNative (Binder.java)
android.os.BinderProxy.transact (Binder.java:503)
android.content.pm.IPackageManager$Stub$Proxy.getPackageInfo (IPackageManager.java:2684)
android.app.ApplicationPackageManager.getPackageInfo (ApplicationPackageManager.java:193)
com.tawkon.data.lib.util.ParameterUtils.getAppVersion (ParameterUtils.java:44)
com.tawkon.data.lib.helper.analytics.NetworkRequestHelper.generateHttpRequest (NetworkRequestHelper.java:28)
com.tawkon.data.lib.service.DataThroughputScanJobIntentService$2.onTestFinished (DataThroughputScanJobIntentService.java:342)
com.tawkon.data.lib.collector.DataThroughputManager$1.run (DataThroughputManager.java:171)
Run Code Online (Sandbox Code Playgroud)
设备规格为三星,操作系统为 6。
就我而言,这似乎是一次罕见的崩溃。无论如何,什么可能导致这种情况发生?我怎样才能防止它再次发生?
我是 Django 的新手,对这个框架的经验为 0。
我从 git 克隆了一个项目,它带有 requirements.txt 文件,但我不知道如何运行它。是否需要先创建虚拟环境,将项目克隆到虚拟环境目录下,然后安装需求?
我是否需要先将项目克隆到某个文件夹中,然后在该文件夹中创建虚拟环境,然后安装需求?
我是否需要使用任何特殊的 IDE 来运行该项目?我尝试在 PyCharm 中打开项目,没有先创建虚拟环境,它问我是否要安装要求。
如果有人可以解释运行现有项目的正确方法是什么,我会很高兴。
我想在我的应用程序中添加可折叠标题。我为标题视图创建了一个单独的组件。
interface Props{
userData: UserDetails | null
scrollY: Animated.Value
}
const HEADER_EXPANDED_HEIGHT = sizeProportionHeight(320)
const HEADER_COLLAPSED_HEIGHT = sizeProportionHeight(142)
const CollapsableHeader : React.FC<Props> = ({userData, scrollY}) => {
const headerHeight = scrollY.interpolate({
inputRange: [0, HEADER_EXPANDED_HEIGHT-HEADER_COLLAPSED_HEIGHT],
outputRange: [HEADER_EXPANDED_HEIGHT, HEADER_COLLAPSED_HEIGHT],
extrapolate: 'clamp'
})
return(
<Animated.View style={{height: headerHeight, width: SCREEN_WIDTH, position:'absolute', top:0, left: 0}}/>
)
}
export default CollapsableHeader
Run Code Online (Sandbox Code Playgroud)
我的主页我添加了标题,如下所示:
interface Props{
navigation: StackNavigationProp<MainParamList,'HomeScreen'>
route: RouteProp<MainParamList,'HomeScreen'>
}
interface HeaderState {
scrollY: Animated.Value
}
interface HomeScreenState {
header: HeaderState
}
const HomeScreen : React.FC<Props> = …
Run Code Online (Sandbox Code Playgroud) react-native react-native-scrollview react-animated react-native-animatable react-typescript
我想在我的搜索视图中为用户创建提示,但是在用户按下放大镜图标之前,提示不可见.即使用户没有像编辑文本那样点击任何内容,有没有办法显示提示?此外,我希望搜索视图的边框可见而不仅仅是图标,有没有办法实现它?提前致谢.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/header_image_id"
android:orientation="vertical"
android:layoutDirection="rtl">
<TextView
android:id="@+id/text_view_id"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAlignment="center"
android:text="Enter your search request here?"/>
<SearchView
android:id="@+id/search_view_id"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:queryHint="This is a hint" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我想在我的数据库中存储操作的时间戳。问题是我得到的时间datetime.datetime.now()
不正确(我猜这是由于时区)。我尝试使用 python 获取终端中的值并得到了正确的结果。
import datetime
datetime.datetime.now()//correct time
Run Code Online (Sandbox Code Playgroud)
但是,如果我在问题执行期间打印结果,则输出不正确,结果会提前两个小时。
为什么会这样,终端给了我正确的时间,但程序实例却没有,我怎样才能在程序中获得正确的时间?
编辑: 来自终端的日期时间:
2018-08-30 17:41:04.413187
Run Code Online (Sandbox Code Playgroud)
程序实例的日期时间:
2018-08-30 14:42:31.761310
Run Code Online (Sandbox Code Playgroud)
编辑:
我注意到运行程序时出现此警告。
RuntimeWarning: DateTimeField Policy.last_update received a naive datetime (2018-08-30 15:16:23.689896) while time zone support is active.
RuntimeWarning)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用这两行将图标添加到我的工具栏
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.logo);
Run Code Online (Sandbox Code Playgroud)
图标已添加,但它添加在工具栏的中心,例如,如何将其添加到工具栏的右上角?
这是我的 action_bar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="#ffffff"
android:id="@+id/action_bar_text"
android:textSize="18sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) android ×4
asp.net-mvc ×1
axios ×1
datetime ×1
django ×1
https ×1
mongodb ×1
mongoose ×1
node.js ×1
python ×1
react-native ×1
searchview ×1
typescript ×1