0
我想從我的android應用程序發送一些數據到在android中使用HttpClient的aspx頁面。我將發送我的用戶名和密碼在aspx頁面內進行驗證。這是我做過什麼對Android的一面:從android接收數據到aspx頁面並返回響應
//安卓側
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);
我這樣做的原因是因爲我要檢查,我從機器人傳遞的數據將被ASPX閱讀頁面代碼在後面。
如何使用從Android發送的字符到Aspx頁面?
這是我做的aspx頁面上:
//的.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>
和後面的代碼(網頁加載部分):
//後面的代碼
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>");
}
}
我在做什麼正確的?我能使用Request.Form從android獲得postdata嗎?如果是這樣,它會丟回我回復給Android的迴應嗎?