Support
Quality
Security
License
Reuse
kandi has reviewed android-volley and discovered the below as its top functions. This is intended to give you an instant insight into android-volley implemented functionality, and help decide if they suit your requirements.
DEPRECATED
Gradle
compile 'com.mcxiaoke.volley:library:1.0.19'
License
Copyright (C) 2014,2015,2016 Xiaoke Zhang
Copyright (C) 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Volley local request only works when attached to USB debugging
http://10.0.2.2/myserverfile.php
-----------------------
2021-01-25 12:02:53.881 4942-1564/system_process D/ConnectivityService: Returning BLOCKED NetworkInfo to uid=xxx
In Android ,Volley , How to pass a single string Parameter and receive a string result?
String url = "http://192.168.1.20:88/Home/testme?a=abc";
-----------------------
String url = "http://192.168.1.20:88/Home/testme?a=abc";
Volley POST with URL ENCODED parameters not being passed
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.ServerError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
/**
* Logcat tag
*/
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText usernameEditText = findViewById(R.id.username);
final EditText passwordEditText = findViewById(R.id.password);
final Button loginButton = findViewById(R.id.login);
final ProgressBar loadingProgressBar = findViewById(R.id.loading);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
String url = "https://logintest.moveon.pro/";
// Request a string response from the provided URL.
StringRequest sr = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("HttpClient", "success! response: " + response.toString());
// Display the first 500 characters of the response string.
usernameEditText.setText("Response is: " + response.toString().substring(0, 500));
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
usernameEditText.setText("That didn't work!");
// As of f605da3 the following should work
NetworkResponse response = error.networkResponse;
if (error instanceof ServerError && response != null) {
try {
String res = new String(response.data,
HttpHeaderParser.parseCharset(response.headers, "utf-8"));
// Now you can use any deserializer to make sense of data
JSONObject obj = new JSONObject(res);
usernameEditText.setText(usernameEditText.getText() + res);
} catch (UnsupportedEncodingException e1) {
// Couldn't properly decode data to string
e1.printStackTrace();
} catch (JSONException e2) {
// returned data is not JSONObject?
e2.printStackTrace();
}
}
Log.e("HttpClient", "error: " + error.toString());
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("rest_route", "/simple-jwt-login/v1/auth");
params.put("email", "dummy@gmail.com");
params.put("password", "935jIDan^4S@$rAFLw4w@!$Z");
return params;
}
};
// Add the request to the RequestQueue.
queue.add(sr);
}
});
}
}
Multipart file progress updating faster than actual upload
((HttpURLConnection) urlconnection).setFixedLengthStreamingMode((int) fileInfo.fileSize);
public void main(FileInfo fileInfo, String put, String get, Message message, boolean isRetry) {
URLConnection urlconnection = null;
try {
File file = new File(fileInfo.filePath);
URL url = new URL(put);
urlconnection = url.openConnection();
urlconnection.setDoOutput(true);
urlconnection.setDoInput(true);
if (urlconnection instanceof HttpURLConnection) {
((HttpURLConnection) urlconnection).setRequestMethod("PUT");
((HttpURLConnection) urlconnection).setFixedLengthStreamingMode((int) fileInfo.fileSize);
((HttpURLConnection) urlconnection).setRequestProperty("Content-type", fileInfo.fileMimeType);
((HttpURLConnection) urlconnection).setRequestProperty("Content-length", String.valueOf(fileInfo.fileSize));
((HttpURLConnection) urlconnection).setRequestProperty("host", XMPP_SERVER);
((HttpURLConnection) urlconnection).connect();
}
BufferedOutputStream bos = new BufferedOutputStream(urlconnection.getOutputStream());
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
long transferred = 0;
int i = 0;
byte[] buffer = new byte[4096];
while ((i = bis.read(buffer)) > 0) {
bos.write(buffer, 0, i);
transferred += i;
int progress = (int) ((transferred * 1000.0f) / fileInfo.fileSize);
if (fileUploadListener != null) {
fileUploadListener.onProgressChanged(message, progress);
}
}
bis.close();
bos.close();
InputStream inputStream;
int responseCode = ((HttpURLConnection) urlconnection).getResponseCode();
if ((responseCode >= 200) && (responseCode <= 202)) {
inputStream = ((HttpURLConnection) urlconnection).getInputStream();
int j;
while ((j = inputStream.read()) > 0) {
System.out.println(j);
}
if (responseCode == 200) {
if (fileUploadListener != null)
fileUploadListener.onAttachmentFileUpload(generateImageUploadResponse(false, get), message, isRetry);
} else {
if (fileUploadListener != null)
fileUploadListener.onAttachmentFileUpload(generateImageUploadResponse(true, ""), message, isRetry);
}
} else {
inputStream = ((HttpURLConnection) urlconnection).getErrorStream();
if (fileUploadListener != null)
fileUploadListener.onAttachmentFileUpload(generateImageUploadResponse(true, ""), message, isRetry);
}
((HttpURLConnection) urlconnection).disconnect();
} catch (Exception e) {
e.printStackTrace();
if (fileUploadListener != null)
fileUploadListener.onAttachmentFileUpload(generateImageUploadResponse(true, ""), message, isRetry);
}
}
-----------------------
((HttpURLConnection) urlconnection).setFixedLengthStreamingMode((int) fileInfo.fileSize);
public void main(FileInfo fileInfo, String put, String get, Message message, boolean isRetry) {
URLConnection urlconnection = null;
try {
File file = new File(fileInfo.filePath);
URL url = new URL(put);
urlconnection = url.openConnection();
urlconnection.setDoOutput(true);
urlconnection.setDoInput(true);
if (urlconnection instanceof HttpURLConnection) {
((HttpURLConnection) urlconnection).setRequestMethod("PUT");
((HttpURLConnection) urlconnection).setFixedLengthStreamingMode((int) fileInfo.fileSize);
((HttpURLConnection) urlconnection).setRequestProperty("Content-type", fileInfo.fileMimeType);
((HttpURLConnection) urlconnection).setRequestProperty("Content-length", String.valueOf(fileInfo.fileSize));
((HttpURLConnection) urlconnection).setRequestProperty("host", XMPP_SERVER);
((HttpURLConnection) urlconnection).connect();
}
BufferedOutputStream bos = new BufferedOutputStream(urlconnection.getOutputStream());
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
long transferred = 0;
int i = 0;
byte[] buffer = new byte[4096];
while ((i = bis.read(buffer)) > 0) {
bos.write(buffer, 0, i);
transferred += i;
int progress = (int) ((transferred * 1000.0f) / fileInfo.fileSize);
if (fileUploadListener != null) {
fileUploadListener.onProgressChanged(message, progress);
}
}
bis.close();
bos.close();
InputStream inputStream;
int responseCode = ((HttpURLConnection) urlconnection).getResponseCode();
if ((responseCode >= 200) && (responseCode <= 202)) {
inputStream = ((HttpURLConnection) urlconnection).getInputStream();
int j;
while ((j = inputStream.read()) > 0) {
System.out.println(j);
}
if (responseCode == 200) {
if (fileUploadListener != null)
fileUploadListener.onAttachmentFileUpload(generateImageUploadResponse(false, get), message, isRetry);
} else {
if (fileUploadListener != null)
fileUploadListener.onAttachmentFileUpload(generateImageUploadResponse(true, ""), message, isRetry);
}
} else {
inputStream = ((HttpURLConnection) urlconnection).getErrorStream();
if (fileUploadListener != null)
fileUploadListener.onAttachmentFileUpload(generateImageUploadResponse(true, ""), message, isRetry);
}
((HttpURLConnection) urlconnection).disconnect();
} catch (Exception e) {
e.printStackTrace();
if (fileUploadListener != null)
fileUploadListener.onAttachmentFileUpload(generateImageUploadResponse(true, ""), message, isRetry);
}
}
QUESTION
"error":true,"message":"required parameters are not available" while checking api call using postman
Asked 2021-Aug-28 at 17:38i am learning how to connect android app with php admin panel with volley and for this i used a tutorial from Javatpoint , but i made two files as they told me to create and checked apicall in Postman web, i got this error:
"error":true,"message":"required parameters are not available"
here is the structure of the tables where i want to get data from.
can anyone help me about this error, i really don't know how to solve it.
<?php
require_once 'connection.php';
$response = array();
if(isset($_GET['apicall'])){
switch($_GET['apicall']){
case 'signup':
if(isTheseParametersAvailable(array('username','email','password',))){
$username = $_POST['username'];
$email = $_POST['email'];
$password = md5($_POST['password']);
$stmt = $conn->prepare("SELECT user_id FROM ci_users WHERE username = ? OR email = ?");
$stmt->bind_param("ss", $username, $email);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){
$response['error'] = true;
$response['message'] = 'User already registered';
$stmt->close();
}
else{
$stmt = $conn->prepare("INSERT INTO ci_users (username, email, password,) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $username, $email, $password);
if($stmt->execute()){
$stmt = $conn->prepare("SELECT user_id,id, username, email, FROM users WHERE username = ?");
$stmt->bind_param("s",$username);
$stmt->execute();
$stmt->bind_result($user_id, $id, $username, $email);
$stmt->fetch();
$user = array(
'id'=>$id,
'username'=>$username,
'email'=>$email,
);
$stmt->close();
$response['error'] = false;
$response['message'] = 'User registered successfully';
$response['user'] = $user;
}
}
}
else{
$response['error'] = true;
$response['message'] = 'required parameters are not available';
}
break;
case 'login':
if(isTheseParametersAvailable(array('username', 'password'))){
$username = $_POST['username'];
$password = md5($_POST['password']);
$stmt = $conn->prepare("SELECT user_id, username, email, mobile_no FROM ci_users WHERE username = ? AND password = ?");
$stmt->bind_param("ss",$username, $password);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){
$stmt->bind_result($id, $username, $email, $mobile);
$stmt->fetch();
$user = array(
'id'=>$id,
'username'=>$username,
'email'=>$email,
'mobile'=>$mobile
);
$response['error'] = false;
$response['message'] = 'Login successfull';
$response['user'] = $user;
}
else{
$response['error'] = false;
$response['message'] = 'Invalid username or password';
}
}
break;
default:
$response['error'] = true;
$response['message'] = 'Invalid Operation Called';
}
}
else{
$response['error'] = true;
$response['message'] = 'Invalid API Call';
}
echo json_encode($response);
function isTheseParametersAvailable($params){
foreach($params as $param){
if(!isset($_POST[$param])){
return false;
}
}
return true;
}
?>
ANSWER
Answered 2021-Aug-28 at 13:00Looking at your screenshot and php code you have provided. You may have forgot to send three post parameters namely 'username','email','password' in the body of the request. Which is checked by the function isTheseParametersAvailable in the api endpoint. As given in https://www.javatpoint.com/android-volley-library-registration-login-logout. Your postman request body should look like below.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit