Following is my Android code and Response:
public InputStream HTTP_POST(String URL,List<NameValuePair> mNameValuePairs)
{
HttpClient mHttpClient = new DefaultHttpClient();
try
{
URL url = new URL("http", "192.168.0.126", 3000, "/tests.json");
Log.d("URL", url.toString());
/*Log.d("URL", URL);
URI baseURL = new URI(URL);*/
HttpPost mHttpPost = new HttpPost(url.toURI());
if(mNameValuePairs!=null)
{
mHttpPost.setEntity(new UrlEncodedFormEntity(mNameValuePairs));
}
HttpResponse mHttpResponse = mHttpClient.execute(mHttpPost);
Log.d("status code",""+getResponseStatusCode(mHttpResponse));
if(getResponseStatusCode(mHttpResponse) == 200)
{
HttpEntity mHttpEntity = mHttpResponse.getEntity();
return mHttpEntity.getContent();
}
else
{
Log.d("Error", ""+getResponseStatusCode(mHttpResponse));
return null;
}
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
----------------------
private class PostTest extends AsyncTask<String, Void, String>
{
private ProgressDialog mProgressDialog = null;
String name = null;
String details = null;
@Override
protected void onPreExecute()
{
super.onPreExecute();
mProgressDialog = new ProgressDialog(LoginForm.this);
mProgressDialog.setMessage(Constant.MSG_PROGRESSBAR_WAITING);
mProgressDialog.setCancelable(false);
mProgressDialog.setCanceledOnTouchOutside(false);
mProgressDialog.show();
name = editTextLogin.getText().toString().trim();
details = editTextPassword.getText().toString().trim();
}
@Override
protected String doInBackground(String... params)
{
try
{
String baseUrl = "http://192.168.0.126:3000/tests/";
List<NameValuePair> mNameValuePairs = new ArrayList<NameValuePair>();
mNameValuePairs.add(new BasicNameValuePair("name", name));
mNameValuePairs.add(new BasicNameValuePair("description", details));
return common.InputStreamToString(common.HTTP_POST(baseUrl, mNameValuePairs));
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
}
@Override
protected void onPostExecute(String response)
{
super.onPostExecute(response);
mProgressDialog.dismiss();
try
{
if(response != null)
{
Log.d("response", response);
}
else
{
Toast.makeText(LoginForm.this, "Login Failed... Try again", Toast.LENGTH_SHORT).show();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
--------------------------
Response which I got from this code:
{"name":null,"created_at":"2013-01-11T05:31:39Z","updated_at":"2013-01-11T05:31:39Z","description":null,"id":106}