0

In my app, I need some string to be downloaded from server to use in the app. How can I upload the strings to the server?.

I've uploaded a text file at first but when sending request I received this error in logcat:

Unexpected response code 307 for:

Also, I uploaded my text in a web page body same error happened.
Please help me how to upload some text or an ArrayList to the server and download with volley and use in the app.

This is my volley request method:

private void getOnlinePrice (){
   StringRequest request=new StringRequest(Request.Method.GET,URI_SHOW_PARAMS, new Response.Listener<String>() {
       @Override
       public void onResponse(String response) {
           String s=response;
           txtinfo.setText(s);
       }
   }, new Response.ErrorListener() {
       @Override
       public void onErrorResponse(VolleyError error) {

       }
   });
   requestQueue.add(request);
}
Son Truong
  • 13,661
  • 5
  • 32
  • 58
saber javadi
  • 473
  • 1
  • 7
  • 17

1 Answers1

1

You can do this:

                                 String HTTP_URL = "YOUR URL";




                                    RequestQueue requestQueue = Volley.newRequestQueue(your_activity.this);


                    // sends data using POST method
                                    StringRequest postRequest = new StringRequest(Request.Method.POST, HTTP_URL,
                                            new Response.Listener<String>()
                                            {
                                                @Override
                                                public void onResponse(String response) {

                                                    String resp = response;

                                                    if (!TextUtils.isEmpty(resp))
                                                    {


                                                        Toast.makeText(getApplicationContext(), "my response is" + resp,
                                                                Toast.LENGTH_SHORT).show();



                                                    }
                                                    else{
                // if the response if empty
                                Toast.makeText(getApplicationContext(), "my response is empty",
                                                                Toast.LENGTH_SHORT).show();
                                                    }
                                                }
                                            },
                                            new Response.ErrorListener()
                                            {
                                                @Override
                                                public void onErrorResponse(VolleyError error) {
                                                    // error

                                                }
                                            }
                                    ) {
                                        @Override
                                        protected Map<String, String> getParams()
                                        {
                                            Map<String, String> params = new HashMap<String, String>();
                                            params.put("POST_VARIABLE_1", YourNamestring);
                                            params.put("POST_VARIABLE_2", YourNameString2);

                                            return params;
                                        }
                                    };
                                    requestQueue.add(postRequest);