首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何保存android通过URL返回的数据

如何保存android通过URL返回的数据
EN

Stack Overflow用户
提问于 2015-12-09 21:03:10
回答 1查看 58关注 0票数 1

我已经开始学习restful API,需要一些动力方面的指导。谢谢,我正在尝试将数据存储到SQL服务器中,这是通过URL从Android获取的。我使用的是在visual studio中使用MVC4和实体框架创建的restful API。下面的URL用于获取数据

http://localhost/finalWebAPI/api/Location/ahmad%6078.000%6089.000

我想在ahmad之后保存拆分字符串的值。以下代码是model类中的数据模型

代码语言:javascript
运行
复制
 public class locationdata
{
    public static AndroidDBEntities2 db = new AndroidDBEntities2();


    public static string locationcordinates(string name){
        if (name != null) {
            string[] str = name.Split('%');
            string name1 = str[0];
            string id1 = str[1];
            string id2 = str[2];

            user u = (from u1 in db.users
                      where u1.user_name ==name1

                      select u1).First();

            u.lag = id1;
            u.lng = id2;
             db.SaveChanges()  ;


        }

        return null;

}

这是控制器

代码语言:javascript
运行
复制
     public HttpResponseMessage Get(string id)
{

       var reg1 = locationdata.locationcordinates(id);




 //   var employees = locationdata.UpdateEmployee(name,l);
    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, reg1);
    return response;
}

路线如下

代码语言:javascript
运行
复制
public static void Register(HttpConfiguration config)
    {

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional });
EN

回答 1

Stack Overflow用户

发布于 2015-12-09 22:02:52

请先看下面的链接:

http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api

http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection

默认情况下,web API路由到api/{ControllerNam}并获取HTTP方法以在控制器中选择正确的操作。默认情况下,此URL不指向任何控制器asp.net (localhost/finalWebAPI/api/Location/ahmad%6078.000%6089.000)路由。您必须将其更改为localhost/api/{ControllerNam}/6078.000%6089.000

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34179525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档