Search code examples
androidipportandroid-volleywebrequest

How to send a POST request to ip address with volley (android)


How can you send a stringrequest to a specific ip address and port instead of a url using volley?

My code currently looks like this:

public void onURLPassed(final String urlOfWebsite) {

    Log.d(TAG, "Url passed: " + urlOfWebsite);

    String tag_json_obj = "json_obj_req";

    String serverURL = "http://test.me/api/request/page";

    StringRequest jsonObjReq = new StringRequest(Request.Method.POST,
            serverURL,
            new Response.Listener<String>() {

                @Override
                public void onResponse(String response) {
                    Log.d(TAG, response);
                    String parsedResponse = parse(response); 
                    if (parsedResponse.equals("Error: This is not a valid website")) { 
                        if (isViewAttached()) {
                            getView().displayMessage("This is not a valid website");
                        } else {
                            // error handling
                        }
                        return;
                    }
                    parsedResponse = parsedResponse.replace("\\" + "n", "  \n");
                    parsedResponse = parsedResponse.replace("\\" + "\"", "\"");
                    getView().displayWebsite(parsedResponse.substring(1, parsedResponse.length()-1));
                }
            }, new Response.ErrorListener() {

What I want to do now is send the same POST request to for example 12.123.12.123:40 instead of the serverURL http://test.me/api/request/page

How would I go about doing this?


Solution

  • Volley is an Http library. You can't make a call like this to an ip-address and a port using Volley. See this.