Rajesh Rajendiran Rajesh Rajendiran - 3 months ago 26
Android Question

How to set headers and content-type in android using jackson library (this restful .net web api)

This is .Net web api uri is http://sampleurlapi...../userRegistration/

if using post method JSON

try {
JSONObject jsonobj = new JSONObject();
jsonobj.put("ResNo", -1);
jsonobj.put("DateCreated", "12-12-2015");
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < finalSelectedArrayList.size(); i++) {
JSONObject resobject = new JSONObject();
resobject.put("StySK", finalSelectedArrayList.get(i).getParentSK());
resobject.put("TwrSK", finalSelectedArrayList.get(i).getTwrSK());
resobject .put("BlkSK", finalSelectedArrayList.get(i).getBlkSK());
resobject.put("FlrSK", finalSelectedArrayList.get(i).getFlrSK());
resobject.put("AptSK", finalSelectedArrayList.get(i).getAptSK());
resobject.put("IsDftUt", finalSelectedArrayList.get(i).getDefaultKey());
resobject .put(resobject);

// make web service connection

HttpPost request = new HttpPost(url);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
// Build JSON string

StringEntity entity = new StringEntity(jsonobj.toString());
// Send request to service
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
// Get the status of web service
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

//If the result is returned as NULL, then make the validation to fail.
if ((strValidationResult = rd.readLine()) == null) {
strValidationResult = Boolean.FALSE.toString();

I have Write JSON Like these.

how write json using jackson and set content-type and accept type?

Thanks for advance!

The Request set header like this problem is service side only
HttpPost request = new HttpPost(url);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");