Skip to content Skip to sidebar Skip to footer

How To Set Request Header For Sending Data From Android Apps To Our Server

How to set http header to sending json object from our android apps what type of header we want to use for sending data from client side to server.why we are using header and whats

Solution 1:

you can look into this

you can use this

HttpPostpost=newHttpPost( "http://wwww.testserver.com/userAddMoney" );

post.addHeader( "X-Testing-Auth-Secret" , "kI7wGju76kjhJHGklk76" );

Solution 2:

you can use

try {
            HttpClientclient=newDefaultHttpClient();  
            StringgetURL="http://helloworld.com/getmethod.aspx?id=1&method=getData";
            HttpGethttpGet=newHttpGet(getURL);
            **httpGet .setHeader("Content-Type", "application/x-zip");**
            HttpResponseresponse= client.execute(httpGet);  
            HttpEntityresEntity= response.getEntity();  
            if (resEntity != null) {  
                        //parse response.
                        Log.e("Response",EntityUtils.toString(resEntity));
                    }
    } catch (Exception e) {
        e.printStackTrace();
    }

Solution 3:

try this:

HttpClienthttpclient=newDefaultHttpClient();
HttpPosthttppost=newHttpPost("http://floating-wildwood-1154.herokuapp.com/posts/create_a_post");

// Add Headers
httppost.addHeader("key1", "value1");
httppost.addHeader("key2", "value2");

try {
    // Add your data
    List<NameValuePair> nameValuePairs = newArrayList<NameValuePair>();
    nameValuePairs.add(newBasicNameValuePair("content", valueIWantToSend));
    httppost.setEntity(newUrlEncodedFormEntity(nameValuePairs));
    // Execute HTTP Post RequestHttpResponseresponse= httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}

Solution 4:

Post a Comment for "How To Set Request Header For Sending Data From Android Apps To Our Server"