blissandroid
Lurker
Hi all,
I'm trying to access a web service by "Post"-ing a valid email and password.
It works in google chrome, but I have not gotten it to work in Android.
Below is my attempt to access the web service but I get a
{"status":"500","error":"Internal Server Error"}
error.
Any help would be appreciated...
[HIGH]
class PostToUnilabLogin extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String url = "http://xxx-edetailing.loudcloud.ph/api/v1/login.json";
JSONObject jsonObject = new JSONObject();
try{
jsonObject.put("password", password);
jsonObject.put("email", username);
}catch(JSONException e){
e.printStackTrace();
}
try{
//defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json");
StringEntity se = new StringEntity(jsonObject.toString());
Log.d("xxx", jsonObject.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
//Log.d("JPC", EntityUtils.toString(httpResponse.getEntity()));
HttpEntity httpEntity = httpResponse.getEntity();
//Log.d("JPC", EntityUtils.toString(httpEntity));
is = httpEntity.getContent();
}catch(Exception e){
e.printStackTrace();
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
Log.d("xxx", json);
}catch(Exception e){
}
return null;
}
@Override
protected void onPostExecute(String result){
Log.d("xxx", "onPostExecute");
}
}
[/HIGH]
I'm trying to access a web service by "Post"-ing a valid email and password.
It works in google chrome, but I have not gotten it to work in Android.
Below is my attempt to access the web service but I get a
{"status":"500","error":"Internal Server Error"}
error.
Any help would be appreciated...
[HIGH]
class PostToUnilabLogin extends AsyncTask<String, Integer, String>{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String url = "http://xxx-edetailing.loudcloud.ph/api/v1/login.json";
JSONObject jsonObject = new JSONObject();
try{
jsonObject.put("password", password);
jsonObject.put("email", username);
}catch(JSONException e){
e.printStackTrace();
}
try{
//defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json");
StringEntity se = new StringEntity(jsonObject.toString());
Log.d("xxx", jsonObject.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
//Log.d("JPC", EntityUtils.toString(httpResponse.getEntity()));
HttpEntity httpEntity = httpResponse.getEntity();
//Log.d("JPC", EntityUtils.toString(httpEntity));
is = httpEntity.getContent();
}catch(Exception e){
e.printStackTrace();
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
Log.d("xxx", json);
}catch(Exception e){
}
return null;
}
@Override
protected void onPostExecute(String result){
Log.d("xxx", "onPostExecute");
}
}
[/HIGH]
