Hi,

try the 'setHeader(String name, String value)' method from the HttpGet class. For example:

--- snip ---

DefaultHttpClient client = new DefaultHttpClient();
HttpGet method = new HttpGet(url);
HttpResponse response = null;

method.setHeader("user-agent", getText(R.string.app_name).toString());

try {
        response = client.execute(method);
}
catch(IOException e) {
        e.printStackTrace();
}

--- snip ---

Using setHeader replaces the first header with the same name or if not found it will be added.

Lutz


Am 26.03.2009 um 13:23 schrieb zeeshan:


Hi Experts,

i am trying a GET request to my server with some extra headers
dont know how can i add header


here is my code:

DefaultHttpClient client = new DefaultHttpClient();
            HttpGet method = null;
            HttpResponse resp = null;


method = new HttpGet( new URI(url) );


       } catch (Exception e) {
                 e.printStackTrace();
        }
       try {
                resp = client.execute(method);
       } catch (IOException e) {
                         e.printStackTrace();
        }

///////////////////


i can add header like below but this shows me POST

HttpURLConnection httpConnection = (HttpURLConnection)
url.openConnection();
String boundary = "myboundary";
     httpConnection.setDoOutput(true);
     httpConnection.setDoInput(true);
     httpConnection.setUseCaches(false);

     //httpConnection.setRequestMethod("GET");
     httpConnection.setRequestProperty("Connection","Keep-
Alive");
     httpConnection.setRequestProperty("Content-Type","multipart/form-
data; boundary=" + boundary);
     httpConnection.setRequestProperty("user-agent",this.user_agent);
     httpConnection.setRequestProperty("accept-
language",this.accept_language);
     httpConnection.setRequestProperty("user-agent-
id",this.user_agent_id);
     httpConnection.setAllowUserInteraction(true);
     httpConnection.setInstanceFollowRedirects(true);
     //httpConnection.connect();

     DataOutputStream wr = new DataOutputStream
(httpConnection.getOutputStream());




any solution to add header in GET?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---



Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to