1

I am building a simple android application where I am making a Login Page and implementing a simple POST web API. Previously it was working fine but suddenly it stops working and now it is always returning me HTML code. Below is my code,

 try {

         List<NameValuePair> li = new ArrayList<NameValuePair>();
            li.add(new BasicNameValuePair("username", "[email protected]"));
            li.add(new BasicNameValuePair("password", "123456dndjsj789"));
            li.add(new BasicNameValuePair("key", "ZATXMhjHartjDTrH"));
        HttpClient httpClient = new DefaultHttpClient();
        HttpEntity httpEntity = null;
        HttpResponse httpResponse = null;

            HttpPost httppost = new HttpPost("http://www.deal.com.lb/merchant_ws/login_ws.php");

            httppost.setHeader("Content-Type", "text/html");
            httppost.setHeader("Accept","application/json");

            httppost.setEntity(new UrlEncodedFormEntity(li));

            httpResponse = httpClient.execute(httppost);

        httpEntity = httpResponse.getEntity();
        String response = EntityUtils.toString(httpEntity);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } 

Please tell me which code I had wrote wrong. Also this service is also working as GET request. You can try it in browser. In browser it is working properly but in Android code it is not.

3
  • Incidentally if those are real API credentials, you will need to request a new set from the owner of that service - once you have published them on the web, you can assume that other people will start using them. Commented Jan 20, 2016 at 19:21
  • Ok thanx for your advice Commented Jan 21, 2016 at 2:19
  • Do you have an answer for my question Commented Jan 21, 2016 at 2:20

1 Answer 1

0

Have you set header('Content-Type: application/json'); in your PHP? And have you a trace, log of Java-Code?

Sign up to request clarification or add additional context in comments.

1 Comment

yes, i have set header('Content-Type: application/json') in php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.