Here is How I returned HttpResponseMessage from my ASP.net server like
return Request.CreateResponse(HttpStatusCode.OK,"some string");
And I have accessed the returned response in android with Kaush ION like this
Ion.with(LoginActivity.this)
.load("--URL TO POST--")
.setJsonObjectBody(jsonToSubmit)
.asJsonObject()
.withResponse()
.setCallback(new FutureCallback<Response<JsonObject>>() {
@Override
public void onCompleted(Exception e, Response<JsonObject> result) {
//I want to access header information here
}
Inside onCompleted
Method I can easily access HttpStatusCode
like
int code = result.getHeaders().code();
OR
String statusCode = result.getHeaders().message();
Now My Question is :
How can I get that "some string" which was sent in HttpResponseMessage
with HttpStatusCode
?
----Here is the solution-----
Create a model class StringMsg.cs
public class StringMsg
{
public string Message { get; set; }
}
If you want to send string message and want to retrieve that send it like
StringMsg str = new StringMsg();
str.Message = "some string";
return Request.CreateResponse(HttpStatusCode.OK, str);
Finally, Retrieve The String in onCompleted
Method like this
@Override
public void onCompleted(Exception e, Response<JsonObject> result) {
JsonObject result1 = result.getResult();
String myResult = result1.get("Message"); // Result
}