Post request works in browser but not in mobile apps
We're creating android app, it has a login WebService(http).
The web service is written in .Net, the input and return form of the web service is a json format. When we test the web service in firefox Rest client add-on the output json file seems to be correct as follows
{
"status": true,
"statusdesc": "success",
"userid": "cd2725e7-d0bf-4aac-9e5d-feccd0d40405",
"password": "w1inHr+gPQd+ijxhIWMH/A=="
}
But when I try the same web service in using the following code,
try{
int TIMEOUT_MILLISEC = 30000; // = 30 seconds
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager { new CustomX509TrustManager() }, new SecureRandom());
HttpClient httpClient = new DefaultHttpClient(httpParams);
SSLSocketFactory ssf = new CustomSSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
DefaultHttpClient sslClient = new DefaultHttpClient(ccm, httpClient.getParams());
HttpPost httpPost = new HttpPost(Url);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("data",new StringBody(obj.toString(), Charset.forName("UTF-8")));
httpPost.setEntity(reqEntity);
HttpResponse response = sslClient.execute(httpPost);
StatusCode = response.getStatusLine().getStatusCode();
Log.e("Response", "statuscode " + StatusCode);
HttpEntity entity = response.getEntity();
Log.e("Response String ",""+entity.toString());
if (entity != null) {
responseString = EntityUtils.toString(entity);
}
} catch (Exception e) {
Log.e(TAG, e.toString());
System.out.println(e);
}
The response seems to be as follows
{"userid":null,"password":null,"statusdesc":"Unexpected character encountered while parsing number: Q. Path '', line 1, position 2.rn at Newtonsoft.Json.JsonTextReader.ReadNumberIntoBuffer()rn at Newtonsoft.Json.JsonTextReader.ParseNumber(ReadType readType)rn at Newtonsoft.Json.JsonTextReader.ParseValue()rn at Newtonsoft.Json.JsonTextReader.Read()rn at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)rn at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)rn at CommonWebService.WebServiceCommon.ValidateLogin()","status":false,"emailid":null}
What is to be the issue in mobile code
android .net web-services post
add a comment |
We're creating android app, it has a login WebService(http).
The web service is written in .Net, the input and return form of the web service is a json format. When we test the web service in firefox Rest client add-on the output json file seems to be correct as follows
{
"status": true,
"statusdesc": "success",
"userid": "cd2725e7-d0bf-4aac-9e5d-feccd0d40405",
"password": "w1inHr+gPQd+ijxhIWMH/A=="
}
But when I try the same web service in using the following code,
try{
int TIMEOUT_MILLISEC = 30000; // = 30 seconds
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager { new CustomX509TrustManager() }, new SecureRandom());
HttpClient httpClient = new DefaultHttpClient(httpParams);
SSLSocketFactory ssf = new CustomSSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
DefaultHttpClient sslClient = new DefaultHttpClient(ccm, httpClient.getParams());
HttpPost httpPost = new HttpPost(Url);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("data",new StringBody(obj.toString(), Charset.forName("UTF-8")));
httpPost.setEntity(reqEntity);
HttpResponse response = sslClient.execute(httpPost);
StatusCode = response.getStatusLine().getStatusCode();
Log.e("Response", "statuscode " + StatusCode);
HttpEntity entity = response.getEntity();
Log.e("Response String ",""+entity.toString());
if (entity != null) {
responseString = EntityUtils.toString(entity);
}
} catch (Exception e) {
Log.e(TAG, e.toString());
System.out.println(e);
}
The response seems to be as follows
{"userid":null,"password":null,"statusdesc":"Unexpected character encountered while parsing number: Q. Path '', line 1, position 2.rn at Newtonsoft.Json.JsonTextReader.ReadNumberIntoBuffer()rn at Newtonsoft.Json.JsonTextReader.ParseNumber(ReadType readType)rn at Newtonsoft.Json.JsonTextReader.ParseValue()rn at Newtonsoft.Json.JsonTextReader.Read()rn at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)rn at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)rn at CommonWebService.WebServiceCommon.ValidateLogin()","status":false,"emailid":null}
What is to be the issue in mobile code
android .net web-services post
What is the problem for you? The null's or something else?
– greenapps
Jul 20 '16 at 14:04
when i try in browser result is as status = true, userid seems to be a long character. When i try the same in mobile app it returns as null
– Siva K
Jul 20 '16 at 14:06
We already knew that. You did not answer my question.userid seems to be a long character.
??? Please elaborate.
– greenapps
Jul 20 '16 at 14:09
reqEntity.addPart("data",new StringBody(obj.toString(),
. You are only adding a 'data' parameter. Where is the username and the rest? Moreover you did not tell the type of 'obj' and not what the contents might be. And you did not tell how the server wants the data to be posted. Or how you did it in Firefox. In this way its difficult helping you.
– greenapps
Jul 20 '16 at 14:11
add a comment |
We're creating android app, it has a login WebService(http).
The web service is written in .Net, the input and return form of the web service is a json format. When we test the web service in firefox Rest client add-on the output json file seems to be correct as follows
{
"status": true,
"statusdesc": "success",
"userid": "cd2725e7-d0bf-4aac-9e5d-feccd0d40405",
"password": "w1inHr+gPQd+ijxhIWMH/A=="
}
But when I try the same web service in using the following code,
try{
int TIMEOUT_MILLISEC = 30000; // = 30 seconds
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager { new CustomX509TrustManager() }, new SecureRandom());
HttpClient httpClient = new DefaultHttpClient(httpParams);
SSLSocketFactory ssf = new CustomSSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
DefaultHttpClient sslClient = new DefaultHttpClient(ccm, httpClient.getParams());
HttpPost httpPost = new HttpPost(Url);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("data",new StringBody(obj.toString(), Charset.forName("UTF-8")));
httpPost.setEntity(reqEntity);
HttpResponse response = sslClient.execute(httpPost);
StatusCode = response.getStatusLine().getStatusCode();
Log.e("Response", "statuscode " + StatusCode);
HttpEntity entity = response.getEntity();
Log.e("Response String ",""+entity.toString());
if (entity != null) {
responseString = EntityUtils.toString(entity);
}
} catch (Exception e) {
Log.e(TAG, e.toString());
System.out.println(e);
}
The response seems to be as follows
{"userid":null,"password":null,"statusdesc":"Unexpected character encountered while parsing number: Q. Path '', line 1, position 2.rn at Newtonsoft.Json.JsonTextReader.ReadNumberIntoBuffer()rn at Newtonsoft.Json.JsonTextReader.ParseNumber(ReadType readType)rn at Newtonsoft.Json.JsonTextReader.ParseValue()rn at Newtonsoft.Json.JsonTextReader.Read()rn at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)rn at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)rn at CommonWebService.WebServiceCommon.ValidateLogin()","status":false,"emailid":null}
What is to be the issue in mobile code
android .net web-services post
We're creating android app, it has a login WebService(http).
The web service is written in .Net, the input and return form of the web service is a json format. When we test the web service in firefox Rest client add-on the output json file seems to be correct as follows
{
"status": true,
"statusdesc": "success",
"userid": "cd2725e7-d0bf-4aac-9e5d-feccd0d40405",
"password": "w1inHr+gPQd+ijxhIWMH/A=="
}
But when I try the same web service in using the following code,
try{
int TIMEOUT_MILLISEC = 30000; // = 30 seconds
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager { new CustomX509TrustManager() }, new SecureRandom());
HttpClient httpClient = new DefaultHttpClient(httpParams);
SSLSocketFactory ssf = new CustomSSLSocketFactory(ctx);
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = httpClient.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
DefaultHttpClient sslClient = new DefaultHttpClient(ccm, httpClient.getParams());
HttpPost httpPost = new HttpPost(Url);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("data",new StringBody(obj.toString(), Charset.forName("UTF-8")));
httpPost.setEntity(reqEntity);
HttpResponse response = sslClient.execute(httpPost);
StatusCode = response.getStatusLine().getStatusCode();
Log.e("Response", "statuscode " + StatusCode);
HttpEntity entity = response.getEntity();
Log.e("Response String ",""+entity.toString());
if (entity != null) {
responseString = EntityUtils.toString(entity);
}
} catch (Exception e) {
Log.e(TAG, e.toString());
System.out.println(e);
}
The response seems to be as follows
{"userid":null,"password":null,"statusdesc":"Unexpected character encountered while parsing number: Q. Path '', line 1, position 2.rn at Newtonsoft.Json.JsonTextReader.ReadNumberIntoBuffer()rn at Newtonsoft.Json.JsonTextReader.ParseNumber(ReadType readType)rn at Newtonsoft.Json.JsonTextReader.ParseValue()rn at Newtonsoft.Json.JsonTextReader.Read()rn at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)rn at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)rn at CommonWebService.WebServiceCommon.ValidateLogin()","status":false,"emailid":null}
What is to be the issue in mobile code
android .net web-services post
android .net web-services post
edited Nov 20 at 14:14
piet.t
9,93363245
9,93363245
asked Jul 20 '16 at 14:01
Siva K
2,6331070153
2,6331070153
What is the problem for you? The null's or something else?
– greenapps
Jul 20 '16 at 14:04
when i try in browser result is as status = true, userid seems to be a long character. When i try the same in mobile app it returns as null
– Siva K
Jul 20 '16 at 14:06
We already knew that. You did not answer my question.userid seems to be a long character.
??? Please elaborate.
– greenapps
Jul 20 '16 at 14:09
reqEntity.addPart("data",new StringBody(obj.toString(),
. You are only adding a 'data' parameter. Where is the username and the rest? Moreover you did not tell the type of 'obj' and not what the contents might be. And you did not tell how the server wants the data to be posted. Or how you did it in Firefox. In this way its difficult helping you.
– greenapps
Jul 20 '16 at 14:11
add a comment |
What is the problem for you? The null's or something else?
– greenapps
Jul 20 '16 at 14:04
when i try in browser result is as status = true, userid seems to be a long character. When i try the same in mobile app it returns as null
– Siva K
Jul 20 '16 at 14:06
We already knew that. You did not answer my question.userid seems to be a long character.
??? Please elaborate.
– greenapps
Jul 20 '16 at 14:09
reqEntity.addPart("data",new StringBody(obj.toString(),
. You are only adding a 'data' parameter. Where is the username and the rest? Moreover you did not tell the type of 'obj' and not what the contents might be. And you did not tell how the server wants the data to be posted. Or how you did it in Firefox. In this way its difficult helping you.
– greenapps
Jul 20 '16 at 14:11
What is the problem for you? The null's or something else?
– greenapps
Jul 20 '16 at 14:04
What is the problem for you? The null's or something else?
– greenapps
Jul 20 '16 at 14:04
when i try in browser result is as status = true, userid seems to be a long character. When i try the same in mobile app it returns as null
– Siva K
Jul 20 '16 at 14:06
when i try in browser result is as status = true, userid seems to be a long character. When i try the same in mobile app it returns as null
– Siva K
Jul 20 '16 at 14:06
We already knew that. You did not answer my question.
userid seems to be a long character.
??? Please elaborate.– greenapps
Jul 20 '16 at 14:09
We already knew that. You did not answer my question.
userid seems to be a long character.
??? Please elaborate.– greenapps
Jul 20 '16 at 14:09
reqEntity.addPart("data",new StringBody(obj.toString(),
. You are only adding a 'data' parameter. Where is the username and the rest? Moreover you did not tell the type of 'obj' and not what the contents might be. And you did not tell how the server wants the data to be posted. Or how you did it in Firefox. In this way its difficult helping you.– greenapps
Jul 20 '16 at 14:11
reqEntity.addPart("data",new StringBody(obj.toString(),
. You are only adding a 'data' parameter. Where is the username and the rest? Moreover you did not tell the type of 'obj' and not what the contents might be. And you did not tell how the server wants the data to be posted. Or how you did it in Firefox. In this way its difficult helping you.– greenapps
Jul 20 '16 at 14:11
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38483427%2fpost-request-works-in-browser-but-not-in-mobile-apps%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38483427%2fpost-request-works-in-browser-but-not-in-mobile-apps%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is the problem for you? The null's or something else?
– greenapps
Jul 20 '16 at 14:04
when i try in browser result is as status = true, userid seems to be a long character. When i try the same in mobile app it returns as null
– Siva K
Jul 20 '16 at 14:06
We already knew that. You did not answer my question.
userid seems to be a long character.
??? Please elaborate.– greenapps
Jul 20 '16 at 14:09
reqEntity.addPart("data",new StringBody(obj.toString(),
. You are only adding a 'data' parameter. Where is the username and the rest? Moreover you did not tell the type of 'obj' and not what the contents might be. And you did not tell how the server wants the data to be posted. Or how you did it in Firefox. In this way its difficult helping you.– greenapps
Jul 20 '16 at 14:11