简体   繁体   English

如何从我的Android应用程序传递数据并在我的ASP.NET MVC网站上接收它?

[英]How can I pass data from my android application and receive it on my ASP.NET MVC website?

我想从我的Android应用程序发送一些varibeles到我的ASP.NET网站,所以我可以在那里使用它,我不知道该怎么做。

If your ASP.NET application has some type of public API that would allow it to interact with external applications, you should be able to make a Web Request to it and post the appropriate values that you needed. 如果您的ASP.NET应用程序具有允许其与外部应用程序交互的某种类型的公共API,您应该能够向其发出Web请求并发布所需的适当值。

I'm not terribly familiar with Android syntax, but an example like this one on making HTTP GET/POST requests from Android should point you in the right direction : 我对Android语法并不十分熟悉,但是这样一个关于从Android发出HTTP GET / POST请求的例子应该指向正确的方向:

 // Build your client
 HttpClient httpClient = new DefaultHttpClient();
 HttpPost httpPost = new HttpPost("your-asp-mvc-application/Home/AcceptData"); 

 // Build a collection of data that you want to send
 List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
 nameValuePair.add(new BasicNameValuePair("username", "test_user"));
 nameValuePair.add(new BasicNameValuePair("password", "123456789"));

 // Encoding POST data
 try 
 {
    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
 } 
 catch (UnsupportedEncodingException e) {
    // log exception
    e.printStackTrace();
 }

 // Make the request
 try 
 {
    HttpResponse response = httpClient.execute(httpPost);
    // write response to log
    Log.d("Http Post Response:", response.toString());
 } 
 catch (ClientProtocolException e) 
 {
    // Log exception
    e.printStackTrace();
 } 
 catch (IOException e) 
 {
    // Log exception
    e.printStackTrace();
 }

Basically, once you make make requests, you should be able to target your application and create a Controller Action that can actually accept what you are sending it : 基本上,一旦你发出make请求,你应该能够定位你的应用程序并创建一个Controller Action,它实际上可以接受你发送它的内容:

public ActionResult AcceptData(string username, string password)
{
      // Do something here
}

First, what form of ASP.NET are you using - Forms or MVC? 首先,您使用的是什么形式的ASP.NET - Forms或MVC? Also, what do you mean by "send?" 另外,“发送”是什么意思? Where exactly do you want the data to end up and what exactly do you want your ASP.NET application to do once it receives the data? 您希望数据到底在哪里以及您希望ASP.NET应用程序在收到数据后到底做了什么? If you simply mean that you're creating data in your phone and you want your ASP.NET web site to be able to access it too, you can just insert the data into a database that your ASP.NET web site also has access to (eg through a web service call or something like that). 如果您只是想在手机中创建数据,并且希望ASP.NET网站也能够访问它,那么您只需将数据插入到ASP.NET网站也可以访问的数据库中。 (例如通过网络服务电话或类似的东西)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 android 上“放大”我的 asp.net 网页? - How can I “zoom in” my asp.net webpage on android? 如何在Android和ASP.net MVC之间发送和接收JSON - How to send and receive JSON between Android and ASP.net mvc 如何从Android应用程序接收计算机上的数据 - How to receive data on my Computer from an android application 我可以使用Firebase将数据从Android应用程序传递到ASP.NET(Web窗体),反之亦然吗? - Can I use firebase to pass data from an Android app to ASP.NET (Web Forms) and vice versa? 如何将Android连接到ASP.NET MVC - How can I connect Android to ASP.NET MVC 我可以在为Android应用程序构建的相同“ asp.net mvc Web API”中构建网站/应用程序吗? - can I build a web site/application in the same “asp.net mvc web api” built for an android application? 如何在Android应用程序中打开网站? - How can I open website in my android application? 如何在Android中将图像从Gmail接收到我的应用 - How can i receive image from Gmail to my app in Android 如何从ASP.NET服务器向Android应用发送和接收数据以及通知,反之亦然? - How to send and receive data and notification from ASP.NET server to Android app and vise versa? 从ASP.NET MVC Web应用程序访问android活动 - Accessing android activity from ASP.NET MVC Web Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM