Answer the question
In order to leave comments, you need to log in
How to add data from a remote server to a post request?
There is a post request that sends the request body. This request is sent using the Volley library in Android studio! I want the request data, that is, value, to the application to come from the remote server in the same way, so that these values \u200b\u200bcan be changed at any time. Tell me how this can be implemented?
Request body:
params.put("api_key", "value");
params.put("amount", "value");
params.put("to", "value");
params.put("currency", "value");
public class MainActivity extends AppCompatActivity {
private TextView post_response_data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button post_data = findViewById(R.id.post_data);
post_response_data = findViewById(R.id.post_response_data);
post_data.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
postRequest();
}
});
}
private void postRequest() {
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
String url = "https://faucetpay.io/api/v1/send";
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
post_response_data.setText("Post Data : " + response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
post_response_data.setText("Post Data : Response Failed");
}
}){
@Override
protected Map<String,String> getParams(){
Map<String, String> params = new HashMap<String, String>();
params.put("api_key", "value");
params.put("amount", "value");
params.put("to", "value");
params.put("currency", "value");
return params;
}
@Override
public Map<String,String> getHeaders() throws AuthFailureError{
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
requestQueue.add(stringRequest);
}
}
Answer the question
In order to leave comments, you need to log in
Hello!
There is a post request that sends the request body. This request is sent using the Volley library in Android studio!
I want the request data, that is, value, to the application to come from the remote server in the same way, so that these values \u200b\u200bcan be changed at any time
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question