I'm trying to send some data from my android application to an aspx page using a HttpClient in android. I will be sending my username and password to be validated inside an aspx page. this is what I did on the android side:
//android side
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://10.0.8.38/someapplication/logRemote.aspx");
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username",username.getText().toString().trim()));
nameValuePairs.add(new BasicNameValuePair("password",password.getText().toString().trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
Log.d("extraData", "running");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response);
The reason I am doing this is because I have to check that the data I passed from android will be read by the aspx page code behind.
How can I use the character sent from Android to the Aspx Page?
This is what I did on the aspx page:
// .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoginRemoteWeb.aspx.cs" Inherits="LoginRemoteWeb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
and the code behind(the page load part):
//code behind
protected void Page_Load(object sender, EventArgs e) {
//Request.Form to be sent by values from android
int loop1;
coll = Request.Form;
String[] arr1 = coll.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
Response.Write("Form: " + arr1[loop1] + "<br>");
}
}
Is what I'm doing correct? Will I be able to get the postdata using Request.Form from android? If it is, will it throw back the response I wrote back to Android?