标签: asp.net-web-api

Java以非零退出值2完成 - Android Gradle

我在执行我的Android应用程序时遇到此错误(我清理它然后构建它,但错误仍然存​​在)

  • 同步:好的
  • 制作项目:好的
  • 清洁:好的
  • 运行:错误

错误:任务执行失败':app:dexDebug'.com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'C:\ Program Files\Java\jdk1.7.0 _25\bin\java.exe''以非零退出值2结束

我的gradle文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
    applicationId "com.rzr.rzevallosr.miappdepruebas"
    minSdkVersion 19
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

productFlavors {
}

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

// This library handles authentication and authorization
compile 'com.spotify.sdk:spotify-auth:1.0.0-beta9@aar'
// This library handles music playback
compile 'com.spotify.sdk:spotify-player:1.0.0-beta9@aar' …
Run Code Online (Sandbox Code Playgroud)

android gradle asp.net-web-api build.gradle

134
推荐指数
8
解决办法
13万
查看次数

获取远程主机的IP地址

在ASP.NET中有一个System.Web.HttpRequest类,它包含ServerVariables可以从REMOTE_ADDR属性值为我们提供IP地址的属性.

但是,我找不到类似的方法从ASP.NET Web API获取远程主机的IP地址.

如何获取发出请求的远程主机的IP地址?

c# asp.net-web-api

133
推荐指数
4
解决办法
8万
查看次数

Web API和Web服务有什么区别?

Web APIWeb服务之间有什么区别吗?或者他们是一样的吗?

web-services terminology asp.net-web-api

132
推荐指数
5
解决办法
25万
查看次数

使用AngularJS从ASP.NET Web API方法下载文件

在我的Angular JS项目中,我有一个<a>锚标记,当单击它时会GET向返回文件的WebAPI方法发出HTTP 请求.

现在,我希望在请求成功后将文件下载到用户.我怎么做?

锚标记:

<a href="#" ng-click="getthefile()">Download img</a>
Run Code Online (Sandbox Code Playgroud)

AngularJS:

$scope.getthefile = function () {        
    $http({
        method: 'GET',
        cache: false,
        url: $scope.appPath + 'CourseRegConfirm/getfile',            
        headers: {
            'Content-Type': 'application/json; charset=utf-8'
        }
    }).success(function (data, status) {
        console.log(data); // Displays text data if the file is a text file, binary if it's an image            
        // What should I write here to download the file I receive from the WebAPI method?
    }).error(function (data, status) {
        // ...
    });
}
Run Code Online (Sandbox Code Playgroud)

我的WebAPI方法: …

html javascript c# asp.net-web-api angularjs

132
推荐指数
3
解决办法
19万
查看次数

我应该如何将多个参数传递给ASP.Net Web API GET?

我正在使用.Net MVC4 Web API(希望)实现RESTful api.我需要将一些参数传递给系统并让它执行一些操作,然后返回一个对象列表作为结果.具体来说,我传递了两个日期并返回它们之间的记录.我还跟踪返回的记录,以便后续调用不会在系统中重新处理.

我考虑过几种方法:

  1. 将params序列化为单个JSON字符串并在API中将其分开. http://forums.asp.net/t/1807316.aspx/1

  2. 在查询字符串中传递参数.
    将多个查询参数传递给restful api的最佳方法是什么?

  3. 定义路径中的参数:api/controller/date1/date2

  4. 使用POST本身可以让我传递一个带有params的对象.

  5. 研究ODATA,因为Web API(目前)支持它.我还没有做太多,所以我对它不是很熟悉.

似乎正确的REST实践表明何时提取数据,您应该使用GET.但是,GET也应该是无效的(不会产生副作用),我想知道我的具体实现是否违反了,因为我在API系统中标记了记录,因此我产生了副作用.

它还引出了支持变量参数的问题.如果输入参数列表发生变化,那么如果发生很多事情,必须重新定义选择3的路线将是很繁琐的.如果在运行时定义参数会发生什么......

在任何情况下,对于我的具体实现,哪个选择(如果有的话)似乎最好?

asp.net rest asp.net-mvc asp.net-mvc-4 asp.net-web-api

131
推荐指数
7
解决办法
29万
查看次数

Web应用程序2中的DefaultInlineConstraintResolver错误

我正在使用Web API 2,当我在本地方框上使用IIS 7.5向我的API方法发送POST时,我收到以下错误.

The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'.

Line 21: GlobalConfiguration.Configuration.EnsureInitialized();
Run Code Online (Sandbox Code Playgroud)

我的API都不能使用IIS.但是,我能够使用IIS Express在Visual Studio中运行我的API项目并成功对我的登录API进行POST,但是当我尝试向另一个API调用发出GET请求时,我得到约束解析器错误.

为了解决这个问题,我在Visual Studio中创建了一个全新的Web API 2项目,并开始一次一个地将现有API导入到新项目中并运行它们以确保它们正常工作.在这个新项目中使用IIS Express,我得到了与现有API项目相同的结果.

我在这里错过了什么?即使有一个全新的项目,我也无法在没有遇到这个约束解析器问题的情况下发出GET请求.

c# asp.net api iis asp.net-web-api

131
推荐指数
3
解决办法
5万
查看次数

如何在C#中编写JSON文件?

我需要在C#中使用JSON格式将以下数据写入文本文件.括号对于它是有效的JSON格式很重要.

[
  {
    "Id": 1,
    "SSN": 123,
    "Message": "whatever"

  },
  {
   "Id": 2,
    "SSN": 125,
    "Message": "whatever"
  }
]
Run Code Online (Sandbox Code Playgroud)

这是我的模型类:

public class data
{
    public int Id { get; set; }
    public int SSN { get; set; }
    public string Message { get; set;}
}
Run Code Online (Sandbox Code Playgroud)

c# json json.net asp.net-web-api

130
推荐指数
4
解决办法
26万
查看次数

如何在返回IHttpActionResult时对web api动作方法进行单元测试?

我们假设这是我的行动方法

public IHttpActionResult Get(int id)
{
    var status = GetSomething(id);
    if (status)
    {
        return Ok();
    }
    else
    {
        return NotFound();
    }
}
Run Code Online (Sandbox Code Playgroud)

测试将是

var httpActionResult = controller.Get(1);
Run Code Online (Sandbox Code Playgroud)

如何在此之后检查我的http状态代码?

c# asp.net-web-api asp.net-web-api2

129
推荐指数
4
解决办法
7万
查看次数

Web API控制器中的多个HttpPost方法

我开始使用MVC4 Web API项目,我有多种HttpPost方法的控制器.控制器如下所示:

调节器

public class VTRoutingController : ApiController
{
    [HttpPost]
    public MyResult Route(MyRequestTemplate routingRequestTemplate)
    {
        return null;
    }

    [HttpPost]
    public MyResult TSPRoute(MyRequestTemplate routingRequestTemplate)
    {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

这里MyRequestTemplate表示负责处理通过请求的Json的模板类.

错误:

当我让使用招为请求http://localhost:52370/api/VTRouting/TSPRoutehttp://localhost:52370/api/VTRouting/Route 我得到一个错误:

找到了与请求匹配的多个操作

如果我删除上述方法之一,它工作正常.

Global.asax中

我已经尝试修改默认路由表global.asax,但我仍然收到错误,我认为我在global.asax中定义路由时遇到问题.这是我在global.asax中所做的.

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapHttpRoute(
        name: "MyTSPRoute",
        routeTemplate: "api/VTRouting/TSPRoute",
        defaults: new { }
    );

    routes.MapHttpRoute(
        name: "MyRoute",
        routeTemplate: "api/VTRouting/Route",
        defaults: new { action="Route" }
    );
}
Run Code Online (Sandbox Code Playgroud)

我正在使用POST在Fiddler中发出请求,在RequestBody中为MyRequestTemplate传递json.

c# global-asax asp.net-web-api asp.net-web-api-routing

126
推荐指数
5
解决办法
17万
查看次数

Web API Put Request生成Http 405 Method Not Allowed错误

这是PUT我的Web API上方法的调用- 方法的第三行(我从ASP.NET MVC前端调用Web API):

在此输入图像描述

client.BaseAddresshttp://localhost/CallCOPAPI/.

这是contactUri:

在此输入图像描述

这是contactUri.PathAndQuery:

在此输入图像描述

最后,这是我的405回复:

在此输入图像描述

这是我的Web API项目中的WebApi.config:

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

            config.Routes.MapHttpRoute(
                name: "DefaultApiGet",
                routeTemplate: "api/{controller}/{action}/{regionId}",
                defaults: new { action = "Get" },
                constraints: new { httpMethod = new HttpMethodConstraint("GET") });

            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
            config.Formatters.Remove(config.Formatters.XmlFormatter);
Run Code Online (Sandbox Code Playgroud)

我试着剥离下来获取传递到路径PutAsJsonAsync,以string.Format("/api/department/{0}", department.Id)string.Format("http://localhost/CallCOPAPI/api/department/{0}", department.Id)没有运气.

有没有人有任何想法为什么我得到405错误?

UPDATE

根据请求,这是我的部门控制器代码(我将发布我的前端项目的部门控制器代码,以及WebAPI的部门ApiController代码):

前端部门控制员 …

c# asp.net-mvc json http-status-code-405 asp.net-web-api

125
推荐指数
5
解决办法
15万
查看次数