我试图做POST与HttpURLConnection(我需要使用这种方式,不能使用HttpPost),我想参数添加到连接如
post.setEntity(new UrlEncodedFormEntity(nvp));
Run Code Online (Sandbox Code Playgroud)
哪里
nvp = new ArrayList<NameValuePair>();
Run Code Online (Sandbox Code Playgroud)
有一些数据存储在.我找不到如何将此添加ArrayList到我HttpURLConnection这里的方法:
HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
https.setHostnameVerifier(DO_NOT_VERIFY);
http = https;
http.setRequestMethod("POST");
http.setDoInput(true);
http.setDoOutput(true);
Run Code Online (Sandbox Code Playgroud)
这种尴尬的https和http组合的原因是不需要验证证书.但这不是问题,它可以很好地发布服务器.但是我需要用论据发帖.
有任何想法吗?
重复免责声明:
回到2012年,我不知道如何将参数插入到HTTP POST请求中.我一直在坚持,NameValuePair因为它是在教程中.这个问题可能看似重复,但是,我的2012年自我阅读了其他问题并且它没有使用NameValuePair.事实上,它并没有解决我的问题.
我一直在关注如何从Android应用程序将数据插入数据库的在线教程,除了这个小部分之外,一切都正常
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
Run Code Online (Sandbox Code Playgroud)
NameValuePair和BasicNameValuePair已被弃用,有利于openConnection().如何创建与之相关的新值关联?http://developer.android.com/reference/java/net/URL.html#openConnection()
有谁知道如何使用openConnection创建名称值对?我到处搜寻.
现在,在API 22中不推荐使用namevaluepair.如果我想实现'namevaluepair'接口,我该怎么办?下面是我的代码
package com.example.passpass;
import org.apache.http.NameValuePair;
public class DoubleNameValuePair implements NameValuePair{
String name;
double value;
public DoubleNameValuePair(String name, double value) {
this.name = name;
this.value = value;
}
@Override
public String getName() {
return name;
}
@Override
public String getValue() {
return Double.toString(value);
}
}
Run Code Online (Sandbox Code Playgroud) 在API 22中弃用了旧的Apache内容,我终于开始更新我的网络内容了.
使用openConnection()看起来非常简单.但是,我还没有看到任何用它发送参数的好例子.
我该如何更新此代码?
ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("user_id",String.valueOf(userId)));
httpPost.setEntity(new UrlEncodedFormEntity(param));
Run Code Online (Sandbox Code Playgroud)
现在,NameValuePair并且BasicNameValuePair也被弃用了.
编辑:我的服务器端php代码不期望JSON参数,我不能因为现有用户而突然切换 - 所以建议使用非JSON答案.
EDIT2:我现在只需要针对Android 4.1+.
java parameters android httpurlconnection basicnamevaluepair
我试图将我的联系人号码发送到服务器,以检查我的数据库中是否包含这些号码.数据库和手机地址列表中包含的所有数字最终都应显示在列表视图中.
当使用for each循环('for(String phoneNumberString:aa)')时,我收到此警告:'for'语句不循环...
我怎么解决这个问题?
public class AllUserActivity extends ListActivity {
// Progress Dialog
private ProgressDialog pDialog;
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> usersList;
// url to get all users list
private static String url_all_user = "http://.../.../.../get_user.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_USER = "user";
private static final String TAG_PHONE = "phone";
private static final String TAG_UID = "uid";
private static final String TAG_USERNAME …Run Code Online (Sandbox Code Playgroud)