-3

How can i Parse url with curly brackets like http://example.com/api/login/{username}/{password} in an android application.

Normal volley post request returns html.But i need JSON.

Integrating Login API in Android App

Ani
  • 21
  • 3
  • 1
    That's really unclear what your'e asking for. Do you want to get the username and password from the url or do you want to send a GET request? where does the JSON takes part here? please clarify yourself. – FlyingNades Apr 07 '18 at 13:20
  • I want to get sucess response from the url by passing username and password as parameters to the above url with curly brackets,But i got html response of website not Json response. – Ani Apr 07 '18 at 13:29
  • What is your problem? – FlyingNades Apr 07 '18 at 13:31
  • My problem is..This is the Login webservice-http://example.com/api/login/ {username}/{password}.I have a login screen with username and password i want to post this parameters to the above mentioned url. – Ani Apr 07 '18 at 13:36

1 Answers1

0

If I get you right, what you want to do is send a GET request for login.

The following code can help you (it is not recommended to use GET for login, use POST instead. I'm giving a GET ex because that's what your'e asking for):

final TextView mTextView = (TextView) findViewById(R.id.text);
// ...

// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://example.com/api/login/your_username/your_password";

// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        // Display the first 500 characters of the response string.
        mTextView.setText("Response is: "+ response.substring(0,500));
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        mTextView.setText("That didn't work!");
    }
});
FlyingNades
  • 432
  • 3
  • 16
  • Thank you for your comment.Can you share post request and I have one more doubt ..Check my url there is curly brackets for username and password. – Ani Apr 07 '18 at 13:50
  • The curly brackets doesnt make any change. [post example](https://stackoverflow.com/a/2938787/5605732). And if one of the answers here helped you with your problem, consider marking it with check mark to the left to let people know this question is answered. – FlyingNades Apr 07 '18 at 13:54