【问题标题】:Receiving data from android to aspx page and return response从android接收数据到aspx页面并返回响应
【发布时间】:2014-11-24 16:17:08
【问题描述】:

我正在尝试使用 android 中的 HttpClient 将一些数据从我的 android 应用程序发送到 aspx 页面。我将发送我的用户名和密码以在 aspx 页面内进行验证。这就是我在 android 端所做的:

//安卓端

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); 

我这样做的原因是因为我必须检查我从android传递的数据是否会被后面的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>");
}

}

我做的对吗?我能否使用 Android 的 Request.Form 获取 postdata?如果是,会不会把我写回给 Android 的响应扔回去?

【问题讨论】:

    标签: c# android asp.net httpresponse


    【解决方案1】:

    您可以在 aspx 页面中创建 webmethod。您也可以在android中设置httppost或httpget的webmethod属性作为您的要求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-25
      • 2011-08-18
      • 2012-04-18
      • 2013-12-29
      • 1970-01-01
      • 1970-01-01
      • 2013-03-20
      • 1970-01-01
      相关资源
      最近更新 更多