I am trying to POST a data from android to restful webservices using loopj.Web services is working fine with POSTMAN testing. When i try to post its failing and i get following message in logcat.
cz.msebera.android.httpclient.client.HttpResponseException: Unsupported Media Type
From the error i think i am not adding Content-Type - application/json to the header. I saw few examples on how to add. But its really confusing.can someone help me.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etemployeeId = (EditText)findViewById(R.id.employeeId);
etfirstName = (EditText)findViewById(R.id.firstName);
buttonRegister = (Button) findViewById(R.id.btnRegister);
buttonRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
registerUser(view);
}
});
getEmployees();
}
public void registerUser(View view) {
RequestParams params = new RequestParams();
String employeeId = etemployeeId.getText().toString();
String firstName = etfirstName.getText().toString();
params.put("employeeId", employeeId);
params.put("firstName", firstName);
EmployeeRestClient.post("RestExample/employee", params, new JsonHttpResponseHandler(){
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
super.onSuccess(statusCode, headers, response);
Log.d("Callback", "onSuccess response");
Toast.makeText(MainActivity.this,
"You are successfully registered!", Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
super.onFailure(statusCode, headers, responseString, throwable);
Log.d("Callback", "onFailure responseString");
Toast.makeText(MainActivity.this,
"failed", Toast.LENGTH_LONG).show();
}
});
}
}