0

这是移动代码..我正在将数据从移动设备发送到网站..我只需要知道如何在网站上获取数据并存储在数据库中?

这是从 android 手机在网站上发送数据的代码示例。

    HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http:mywebsite.cshtml");
try {
          List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(9);


          nameValuePairs.add(new BasicNameValuePair("deviceId", devid));
          nameValuePairs.add(new BasicNameValuePair("fname", fname));
          nameValuePairs.add(new BasicNameValuePair("lanme", lname));
          nameValuePairs.add(new BasicNameValuePair("age", email));
          nameValuePairs.add(new BasicNameValuePair("city", city));
          nameValuePairs.add(new BasicNameValuePair("country", coun));
          nameValuePairs.add(new BasicNameValuePair("gender", gen));
          nameValuePairs.add(new BasicNameValuePair("username", un));
          nameValuePairs.add(new BasicNameValuePair("password", pass));
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
          httpclient.execute(httppost);
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
       // TODO Auto-generated catch block
}

这是html页面的代码。

@{

  var db = Database.Open("EPS");
       var sqlCommand="SELECT * FROM awaitinguser";
       List<awaitingUser>lst=new List<awaitingUser>();

       foreach(var row in db.Query(sqlCommand))
       {
           awaitingUser temp= new awaitingUser();
           temp.deviceid = row.deviceid.ToString();
           temp.fname = row.fname.ToString();
           temp.lname = row.lname.ToString();
           temp.age = row.age.ToString();
           temp.city = row.city.ToString();
           temp.country = row.country.ToString();
           temp.gender = row.gender.ToString();
           temp.un = row.username.ToString();
           temp.pwd = row.password.ToString();

           lst.Add(temp);
           string s="";
       }

}


<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></br></br>EPS - Awaiting Users</title>
    </head>
    <body>
        <div>
            </br></br>

            <ul>

                  @{
                      for(int i=0;i<lst.Count;i++)
                      {

                          var s ="appuser.cshtml?did=" +lst[i].deviceid.ToString(); 
                              <li>


                               <p> Device ID : <strong>@lst[i].deviceid</strong></p>
                               <p> First Name : <strong>@lst[i].fname</strong></p>
                               <p> Last Name : <span>@lst[i].lname</span><br /></p>
                               <p> Age : <span>@lst[i].age</span><br /></p>
                               <p> City : <span>@lst[i].city</span><br /></p>
                               <p> Country : <span>@lst[i].country</span><br /></p>
                               <p> Gender : <span>@lst[i].gender</span><br /></p>
                               <p> Username : <span>@lst[i].un</span><br /></p>
                               <p> Password : <span>@lst[i].pwd</span><br /><br/></p>


                                Approve User : <a href="@Href("~/appuser.cshtml", @s)" style ="font-size: 15px;color: #0094ff">  Yes </a>  
                                        <a href="@Href("~/declineuser.cshtml", @s)" style ="font-size: 15px;color: #0094ff">  No </a><br/><br/>


                              </li>

                           }

                       }

                </ul>

        </div>
        <div>
            <a href="~/EPSHomePage.cshtml" style="color: #0094ff">Go to Home Page</a>
        </div>
    </body>
</html>
4

1 回答 1

0

在页面加载时使用类似这样的东西。

      public class ajax : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)  { Stream dataStream = context.Request.InputStream;
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();
            JavaScriptSerializer json_serializer = new JavaScriptSerializer();
            Dictionary<string, object> data = (Dictionary<string, object>)json_serializer.DeserializeObject(responseFromServer);
            selected_user u = new selected_user();
            u.user_name = data["uname"].ToString();
            u.pass = data["pass"].ToString();
            u.sname = data["lname"].ToString();         

context.Response.Write(yourjsonresult); }

于 2013-06-04T12:26:32.903 回答