小编AK3*_*800的帖子

调用Web API 2端点时,HTTP 415不支持的媒体类型错误

我有一个现有的Web API 2服务,需要修改其中一个方法以将自定义对象作为另一个参数,目前该方法有一个参数,它是来自URL的简单字符串.将自定义对象添加为参数后,从.NET Windows应用程序调用服务时,我现在收到415不支持的媒体类型错误.有趣的是,我可以使用javascript和jquery ajax方法成功调用此方法.

Web API 2服务方法如下所示:

<HttpPost>
<HttpGet>
<Route("{view}")>
Public Function GetResultsWithView(view As String, pPaging As Paging) As HttpResponseMessage
   Dim resp As New HttpResponseMessage
   Dim lstrFetchXml As String = String.Empty
   Dim lstrResults As String = String.Empty

   Try
      '... do some work here to generate xml string for the response
      '// write xml results to response
      resp.Content = New StringContent(lstrResults)
      resp.Content.Headers.ContentType.MediaType = "text/xml"
      resp.Headers.Add("Status-Message", "Query executed successfully")
      resp.StatusCode = HttpStatusCode.OK
   Catch ex As Exception
      resp.StatusCode = HttpStatusCode.InternalServerError
      resp.Headers.Add("Status-Message", String.Format("Error …
Run Code Online (Sandbox Code Playgroud)

vb.net json asp.net-web-api http-status-code-415 asp.net-web-api2

31
推荐指数
4
解决办法
13万
查看次数

jquery $ .ajax调用在Chrome或Firefox中导致401未经授权的响应,但在IE中有效

我有一个在需要使用JQuery $ .ajax方法(目前使用jquery 1.7.2)的网页上运行的脚本向不同域上的服务端点提交几个GET请求.我在IE(9,10,11)中使用了ajax调用,但它在Firefox和Chrome中失败了401 Unauthorized响应.Chrome中的部分其他错误消息是"访问此资源需要完全身份验证".

我的ajax调用设置如下(对于这些失败的请求,dataType为"json",async为true):

    $.ajax({
      url: url,
      type: "GET",
      async: isAsync,
      dataType: dataType,
      username: user,
      password: pswd,
      success: function (response, status) {
         // success code here
      },
      failure: function (response, status) {
         // failure code here
      },
      complete: function (xhr, status) {
         // on complete code here
      }
   });
Run Code Online (Sandbox Code Playgroud)

我传递了访问该服务所需的用户名和密码,这在IE中有效.我理解JQuery ajax函数将正确处理身份验证,因此如果响应返回指示需要授权,它将使用提供的凭据来正确地生成该请求.我在这里错过了什么吗?我是否需要手动添加Authorization标头才能生效?

更新:以下是Chrome和IE通过F12调试工具报告的请求,响应和Cookie信息(某些信息已替换为[...已删除...])

铬(42.0.2311.90米)

响应标题

access-control-allow-credentials:true access-control-allow-origin:[... removed ...] access-control-expose-headers:cache-control:private,max-age = 0,must-revalidate connection :keep-alive content-encoding:gzip content-length:296 content-type:text/html; charset = ISO-8859-1 date:Tue,21 Apr 2015 20:55:12 GMT expires:Tue,2015年4月21日20 :55:12 GMT p3p:CP …

javascript ajax jquery http-status-code-401

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

在ReportExecution2005.asmx SSRS服务上调用Render方法时,snapshotID参数类型不匹配

我正在尝试使用带有MSSQL 2012后端的SSRS 2012服务器上的ReportExecution2005.asmx服务端点将报告呈现为PDF.当我在Web服务上调用Render方法时,我收到以下错误:为'snapshotID'提供的参数值与参数类型不匹配.---> Microsoft.ReportingServices.Diagnostics.Utilities.ParameterTypeMismatchException:为'snapshotID'提供的参数值与参数类型不匹配.---> System.FormatException:String未被识别为有效的DateTime

我尝试呈现的任何报表都出现此错误,snapshotID不是报表上的参数,并且检查报表的配置,它们未设置为缓存或使用快照.我们刚刚从MSSQL 2005迁移到2012,使用带有SSRS和SQL 2005的ReportExecution2005端点我从未看到过这个错误,它工作正常.我已经尝试将snapshotID添加为具有不同值的参数,例如空字符串,当前时间等,但这显然不是它正在寻找的内容.下面是我用来设置和调用服务上的Render方法的代码.在我的情况下pstrExportFormat将是"PDF"

   Public Function ExportReport(pstrReportPath As String, plstParams As List(Of ReportParameter), pstrExportFormat As String) As Byte()
  Dim lResults() As Byte = Nothing
  Dim lstrSessionId As String
  Dim execInfo As New reporting.ExecutionInfo
  Dim execHeader As New reporting.ExecutionHeader
  Dim lstrHistoryId As String = String.Empty

  Try
     Dim rs As New reporting.ReportExecutionService
     Dim deviceInfo As String = "<DeviceInfo><PageHeight>8.5in</PageHeight><PageWidth>11in</PageWidth><MarginLeft>0.25in</MarginLeft><MarginRight>0.25in</MarginRight><MarginTop>0.25in</MarginTop><MarginBottom>0.25in</MarginBottom></DeviceInfo>"
     rs.Credentials = System.Net.CredentialCache.DefaultCredentials
     Dim params As New List(Of reporting.ParameterValue)
     Dim param As reporting.ParameterValue
     rs.Credentials = System.Net.CredentialCache.DefaultCredentials

     For Each lInputParam In …
Run Code Online (Sandbox Code Playgroud)

sql-server web-services reporting-services

5
推荐指数
1
解决办法
1573
查看次数

将新的项目数组拼接到现有的Knockout可观察数组会导致绑定错误

当网页加载时,我有一个挖出的可观察数组填充了一些初始值,并且当用户与页面交互时,我想通过splice方法添加到可观察数组.我试图添加到数组的新项目与数组中的原始项目具有完全相同的属性,但是当我尝试将新项目拼接到现有数组时,我得到一个Knockout绑定错误,例如:" 错误:无法解析绑定.消息:ReferenceError:未定义ContactName;绑定值:text:ContactName ".即使相关属性确实存在于新数组中的所有项目上,也会发生此错误.我正在尝试在Knockout可观察数组上进行拼接,而不是底层数组对象,因为我希望绑定自动更新.拼接代码如下所示:vmContacts.Contacts.splice(vmContacts.Contacts().length,0,contactData2);.

我在这里创建了一个小提琴示例,以便您可以看到它的实际效果:http://jsfiddle.net/ak47/pMFwe/.单击"添加联系人"按钮时,您将在浏览器控制台中看到错误.

我想避免循环遍历新对象数组,为我需要添加的每个项目执行push(),这就是拼接应该工作的地方,但事实并非如此.这是Knockout中的已知问题还是我做错了什么?谢谢您的帮助!

knockout.js

4
推荐指数
1
解决办法
4350
查看次数