Do Volley StringRequests work with localhost as the URL?

Multi tool use
Multi tool use












0















I have used Volley StringRequests before but I am trying to run it on localhost to make for easier testing in my case. I have had no response from the webpage. I am Xampp with Apache and SQL turned on to run my local server. Does Volley support use with localhost?



php:



$result = array();
if (isset($_POST['input'])) {
$obj = $_POST["input"]; //gets JSONArray as String with POST method
echo "JSON input: ".$obj."<br>";
$result["success"] = true;
} else {
echo "No data for 'input'";
$result["success"] = false;
}
echo json_encode($result);


java:



public class WebRequest extends StringRequest {
private static final String WebRequestURL = "localhost/practice/";

private Map<String, String> params;

public WebRequest(String input, Response.Listener<String> listener){
super(Method.POST, WebRequestURL, listener, null);
params = new HashMap<>();
params.put("input", input);
}

@Override
public Map<String, String> getParams() {
return params;
}
}

public class MainActivity extends AppCompatActivity {

private final String TAG = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

try {
JSONArray arr = new JSONArray();

JSONObject one = new JSONObject();
one.put("demand", 1);
one.put("location_lat", 89.1234);
one.put("location_lon", -190.1234);
one.put("dest_lat", 89.1234);
one.put("dest_lon", -190.1234);
one.put("time_waiting", 13793);
one.put("id", 5);
arr.put(one);

WebRequest webRequest = new WebRequest(arr.toString(), new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i(TAG, "WebRequest response: " + response);
}
});
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
requestQueue.add(webRequest);
} catch (JSONException e) {
e.printStackTrace();
}
}
}


SOLUTION
I was missing



 uses-permission android:name="android.permission.INTERNET"


in my Manifest










share|improve this question





























    0















    I have used Volley StringRequests before but I am trying to run it on localhost to make for easier testing in my case. I have had no response from the webpage. I am Xampp with Apache and SQL turned on to run my local server. Does Volley support use with localhost?



    php:



    $result = array();
    if (isset($_POST['input'])) {
    $obj = $_POST["input"]; //gets JSONArray as String with POST method
    echo "JSON input: ".$obj."<br>";
    $result["success"] = true;
    } else {
    echo "No data for 'input'";
    $result["success"] = false;
    }
    echo json_encode($result);


    java:



    public class WebRequest extends StringRequest {
    private static final String WebRequestURL = "localhost/practice/";

    private Map<String, String> params;

    public WebRequest(String input, Response.Listener<String> listener){
    super(Method.POST, WebRequestURL, listener, null);
    params = new HashMap<>();
    params.put("input", input);
    }

    @Override
    public Map<String, String> getParams() {
    return params;
    }
    }

    public class MainActivity extends AppCompatActivity {

    private final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {
    JSONArray arr = new JSONArray();

    JSONObject one = new JSONObject();
    one.put("demand", 1);
    one.put("location_lat", 89.1234);
    one.put("location_lon", -190.1234);
    one.put("dest_lat", 89.1234);
    one.put("dest_lon", -190.1234);
    one.put("time_waiting", 13793);
    one.put("id", 5);
    arr.put(one);

    WebRequest webRequest = new WebRequest(arr.toString(), new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
    Log.i(TAG, "WebRequest response: " + response);
    }
    });
    RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
    requestQueue.add(webRequest);
    } catch (JSONException e) {
    e.printStackTrace();
    }
    }
    }


    SOLUTION
    I was missing



     uses-permission android:name="android.permission.INTERNET"


    in my Manifest










    share|improve this question



























      0












      0








      0








      I have used Volley StringRequests before but I am trying to run it on localhost to make for easier testing in my case. I have had no response from the webpage. I am Xampp with Apache and SQL turned on to run my local server. Does Volley support use with localhost?



      php:



      $result = array();
      if (isset($_POST['input'])) {
      $obj = $_POST["input"]; //gets JSONArray as String with POST method
      echo "JSON input: ".$obj."<br>";
      $result["success"] = true;
      } else {
      echo "No data for 'input'";
      $result["success"] = false;
      }
      echo json_encode($result);


      java:



      public class WebRequest extends StringRequest {
      private static final String WebRequestURL = "localhost/practice/";

      private Map<String, String> params;

      public WebRequest(String input, Response.Listener<String> listener){
      super(Method.POST, WebRequestURL, listener, null);
      params = new HashMap<>();
      params.put("input", input);
      }

      @Override
      public Map<String, String> getParams() {
      return params;
      }
      }

      public class MainActivity extends AppCompatActivity {

      private final String TAG = "MainActivity";

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      try {
      JSONArray arr = new JSONArray();

      JSONObject one = new JSONObject();
      one.put("demand", 1);
      one.put("location_lat", 89.1234);
      one.put("location_lon", -190.1234);
      one.put("dest_lat", 89.1234);
      one.put("dest_lon", -190.1234);
      one.put("time_waiting", 13793);
      one.put("id", 5);
      arr.put(one);

      WebRequest webRequest = new WebRequest(arr.toString(), new Response.Listener<String>() {
      @Override
      public void onResponse(String response) {
      Log.i(TAG, "WebRequest response: " + response);
      }
      });
      RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
      requestQueue.add(webRequest);
      } catch (JSONException e) {
      e.printStackTrace();
      }
      }
      }


      SOLUTION
      I was missing



       uses-permission android:name="android.permission.INTERNET"


      in my Manifest










      share|improve this question
















      I have used Volley StringRequests before but I am trying to run it on localhost to make for easier testing in my case. I have had no response from the webpage. I am Xampp with Apache and SQL turned on to run my local server. Does Volley support use with localhost?



      php:



      $result = array();
      if (isset($_POST['input'])) {
      $obj = $_POST["input"]; //gets JSONArray as String with POST method
      echo "JSON input: ".$obj."<br>";
      $result["success"] = true;
      } else {
      echo "No data for 'input'";
      $result["success"] = false;
      }
      echo json_encode($result);


      java:



      public class WebRequest extends StringRequest {
      private static final String WebRequestURL = "localhost/practice/";

      private Map<String, String> params;

      public WebRequest(String input, Response.Listener<String> listener){
      super(Method.POST, WebRequestURL, listener, null);
      params = new HashMap<>();
      params.put("input", input);
      }

      @Override
      public Map<String, String> getParams() {
      return params;
      }
      }

      public class MainActivity extends AppCompatActivity {

      private final String TAG = "MainActivity";

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      try {
      JSONArray arr = new JSONArray();

      JSONObject one = new JSONObject();
      one.put("demand", 1);
      one.put("location_lat", 89.1234);
      one.put("location_lon", -190.1234);
      one.put("dest_lat", 89.1234);
      one.put("dest_lon", -190.1234);
      one.put("time_waiting", 13793);
      one.put("id", 5);
      arr.put(one);

      WebRequest webRequest = new WebRequest(arr.toString(), new Response.Listener<String>() {
      @Override
      public void onResponse(String response) {
      Log.i(TAG, "WebRequest response: " + response);
      }
      });
      RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
      requestQueue.add(webRequest);
      } catch (JSONException e) {
      e.printStackTrace();
      }
      }
      }


      SOLUTION
      I was missing



       uses-permission android:name="android.permission.INTERNET"


      in my Manifest







      php json post localhost android-volley






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 29 '18 at 23:24







      Dane B

















      asked Dec 29 '18 at 22:13









      Dane BDane B

      34




      34
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53973736%2fdo-volley-stringrequests-work-with-localhost-as-the-url%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53973736%2fdo-volley-stringrequests-work-with-localhost-as-the-url%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          hHyZtsQ0mwk,Kqp,4slIhO,KC3FgHEN55C2WDFqwMZEFwSn8A C3 c,j4lryv,GB7etKwZaoZo2AKp,RrvPW,0 kII,GByGz
          azzw,ZXSAjcAo6,L6DDpKJ bmO1Rsl0 XuWtwz6Mr

          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas