When using HTTP to request server, we often pass some parameters to the server, such as IMEI number, platform number, channel number, the client's version number and other general information, such as these parameters we do not have to spell in the URL each time, we can be unified to add to the HTTP header.
1.HttpClient setting of the HTTP header parameters
HttpClient HttpClient = new Defaulthttpclient (); Httpclient.getparams (). Setparameter (Coreconnectionpnames.connection_timeout, conn_time_out); HttpGet httpget = new HttpGet (URL); Httpget.addheader ("Version", Systeminfo.getversionchars ()); Httpget.addheader ("Client_token", Systeminfo.getimei ()); Httpget.addheader ("Platform", Systeminfo.getplatform () + ""); Httpget.addheader ("channel_id", Systeminfo.getchannelid () + "");
2.HttpURLConnection setting of the HTTP header parameters
Httpurlconnection.addrequestproperty ("Version", Systeminfo.getversionchars ()); Httpurlconnection.addrequestproperty ("Client_token", Systeminfo.getimei ()); Httpurlconnection.addrequestproperty ("Platform", Systeminfo.getplatform () + ""), Httpurlconnection.addrequestproperty ("channel_id", Systeminfo.getchannelid () + "");
Or
Httpurlconnection.setrequestproperty ("Version", Systeminfo.getversionchars ()); Httpurlconnection.setrequestproperty ("Client_token", Systeminfo.getimei ()); Httpurlconnection.setrequestproperty ("Platform", Systeminfo.getplatform () + ""), Httpurlconnection.setrequestproperty ("channel_id", Systeminfo.getchannelid () + "");
How Android sets parameters in HTTP header information