我有一个Web API,必须与几个不同的服务进行通信.目前,我将Web API设置为使用以下安全协议:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
当API通过HttpClient(比如Twitter)调用另一个服务时,它将使用该协议.然而,与此同时,另一个请求可能会从云访问某些内容,无论出于何种原因,目前需要TLS(而不是TLS 1.2).在发出之前,对云的请求再次设置安全协议:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
我遇到的问题是当两个独立且唯一的请求进入时,一个用于Twitter,一个用于云,安全协议可能在发送之前切换到"错误的",导致请求失败.
有没有办法在HttpClient每个请求上设置安全协议,这样我就不会在某个单独的某个地方交换设置?
我可以使用.NET的HttpClient来访问Azure Mobile服务吗?
如何使用HttpClient 对移动服务自带的自定义身份验证/授权模式进行身份验证?
这总是返回401,因为我没有传递任何身份验证凭据:
var client = new HttpClient();
var response = client.GetAsync("http://localhost:49190/api/test").Result;
Run Code Online (Sandbox Code Playgroud)
此外,为什么我使用移动服务客户端,为什么我的应用程序密钥,主密钥或用户身份验证密钥总是返回(401)未授权?
客户:
var mobileClient = new MobileServiceClient("http://localhost:49190/", "[my key]");
var response = mobileClient.InvokeApiAsync("test").Result;
Run Code Online (Sandbox Code Playgroud)
服务方面:
[AuthorizeLevel(AuthorizationLevel.Application)]
public class TestController : ApiController
{
public ApiServices Services { get; set; }
// GET api/Test
public string Get()
{
Services.Log.Info("Hello from custom controller!");
return "Hello";
}
}
Run Code Online (Sandbox Code Playgroud) 我可能只花了最后两个小时试图解决这个问题.
我的MVC应用程序抛出的特定错误是:"0x800a01b6 - JavaScript运行时错误:对象不支持属性或方法'datepicker'"
这是我的代码:
_Layout.cshtml:
<head>
...
<script type="text/javascript" src="../../Scripts/jquery-2.0.3.js"></script>
<script type="text/javascript" src="../../Scripts/jquery-ui-1.10.3.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
视图.cshtml
@{
...
Layout = "~/Views/Shared/_Layout.cshtml";
}
...
<div>
Change Time Span:
<br />
From:
<input type="text" id="test" />
</div>
<div class="loading" id="container">@Model.LoadingMessage</div>
<script type="text/javascript">
$(document).ready(function () {
$('#test').datepicker();
});
</script>
Run Code Online (Sandbox Code Playgroud)
我已经看过几个潜在的"重复"问题而没有成功.以下是我看过的一些问题:
MVC3剃刀视图错误Microsoft JScript运行时错误:对象不支持属性或方法'datepicker'`jQuery 在方法datepicker上给出错误"对象不支持此属性或方法" 在MVC 4.0中使用datepicker在db中保留日期值,抛出"对象不支持此属性或方法"
我错过了什么?Intellisense甚至检测到该方法存在,并为我提供了参数放置的建议.
我错过了一些简单的东西吗?