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!
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.