Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 不知道如何将BasicValueNamePair替换为已弃用的_Android - Fatal编程技术网

Android 不知道如何将BasicValueNamePair替换为已弃用的

Android 不知道如何将BasicValueNamePair替换为已弃用的,android,Android,下面是我尝试使用PHP、mysql和xampp服务器创建登录页面的代码。我对BasicValueNamePair有问题,因为它已被弃用。我不知道如何用新代码替换。需要帮忙吗 URL url = new URL("http://10.0.3.2/android_api/check.php"); HttpURLConnection urlConnection =(HttpURLConnection) url.openConnection(); urlConnection.setRequestMeth

下面是我尝试使用PHP、mysql和xampp服务器创建登录页面的代码。我对BasicValueNamePair有问题,因为它已被弃用。我不知道如何用新代码替换。需要帮忙吗

URL url = new URL("http://10.0.3.2/android_api/check.php");
HttpURLConnection urlConnection =(HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.connect();

InputStream in = new BufferedInputStream(urlConnection.getInputStream());
String res = IOUtils.toString(in, "UTF-8");
System.out.println(res + " Blu bluh");

// make sure the url is correct.
//add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
// Always use the same variable name for posting i.e the android side variable name
// and php side variable name should be similar,
nameValuePairs.add(new BasicNameValuePair("Username",username.getText().toString().trim()));
//$Edittext_value = $_POST['Edittext_value'];
nameValuePairs.add(new BasicNameValuePair("Password",password.getText().toString().trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Execute HTTP Post Request
response=httpclient.execute(httppost);

HttpURLConnection是从URLConnection派生的,因此您可以 使用addRequestProperty包含名称-值对

urlConnection.addRequestProperty("Username",username.getText().toString());
请参阅详细信息

这应该会有所帮助