0

Im trying to create a httpGet that returns a similar request as :

http://www.myserver.com/do.json?json={"magazine":"-1"}

I can't seem to get the header right though.... I tried :

    url = "http://www.myserver.com/do.json";
    HttpGet httpGet = new HttpGet(url);
    //httpGet.setHeader("Content-type", "application/json");
    httpGet.addHeader("magazine", "-1");

    HttpResponse response = mHttpClient.execute(httpGet);
    HttpEntity entity= response.getEntity();
    is = entity.getContent();

Can anyone tell me how to do this properly ?? Thanks!

1 Answer 1

8
        HttpGet get;
        HttpParams httpParameters;
try
            {
                httpParameters = new BasicHttpParams();
                String auth = android.util.Base64.encodeToString(
                        (username + ":" + userpwd).getBytes("UTF-8"), 
                        android.util.Base64.NO_WRAP
                    );
                    HttpGet request = new HttpGet(StaticURL.uMain+resourceURI);

                    request.addHeader("Authorization", "Basic "+ auth);

                HttpConnectionParams.setSoTimeout(httpParameters, timeoutConnection);
                client = new DefaultHttpClient(httpParameters);

                response = client.execute(request);
                userAuth = EntityUtils.toString(response.getEntity());

                System.out.println("Data. in login.."+userAuth);


            }

            catch(Exception e)
            {

                System.out.println("Error.."+e);
            }

note: use Base64 api externally

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

2 Comments

Sorry but i still dont get it. What do I have to do to add this : ?json={"magazine":"-1"} to my url when i do the request?
here u hav to use Namepairvalue using http entity search on google

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.