gpt4 book ai didi

java - 不推荐使用 OpenConnection 的 NameValuePair

转载 作者:IT老高 更新时间:2023-10-28 21:08:44 30 4
gpt4 key购买 nike

我一直在关注有关如何将数据从 android 应用程序插入到数据库中的在线教程,并且除了这个小部分之外,一切正常

List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));

NameValuePair 和 BasicNameValuePair 已被弃用,取而代之的是 openConnection()。我怎样才能创建一个新的值(value)关联呢? http://developer.android.com/reference/java/net/URL.html#openConnection()

有谁知道我如何使用 openConnection 创建名称值对?我到处找。

最佳答案

我刚刚遇到了同样的问题。 org.apache.http 中已弃用的类已在 API 23删除

我最终使用了 android.util.Pair。它运行良好,代码也更短:

List<Pair<String, String>> params = new ArrayList<>();
params.add(new Pair<>("username", username));
params.add(new Pair<>("password", password));

关于java - 不推荐使用 OpenConnection 的 NameValuePair,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29378012/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com