[英]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.