来自 MDN
匿名的
执行跨域请求(即,带有 Origin: HTTP 标头)。但是没有发送凭据(即,没有发送 cookie、没有 X.509 证书,也没有发送 HTTP 基本身份验证)。如果服务器没有向源站点提供凭据(通过不设置 Access-Control-Allow-Origin: HTTP 标头),图像将被污染并限制其使用。
使用凭证
发送使用凭证执行的跨域请求(即,使用 Origin: HTTP 标头)(即执行 cookie、证书和 HTTP 基本身份验证)。如果服务器没有向源站点提供凭据(通过 Access-Control-Allow-Credentials: HTTP 标头),图像将被污染并限制其使用。
但是,它们之间的用法区别是什么。
我有以下端点:
[HttpPost("Submit")]
public String post()
{
_ = _service.SubmitMetric("test", MetricType.Count, 60, 1);
return "done";
}
Run Code Online (Sandbox Code Playgroud)
以及服务实现:
public Task<HttpResponseMessage> SubmitMetric(<params>)
{
// build payload
using (var httpClient = new HttpClient())
{
return httpClient.PostAsync(<params>);
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码并调用端点时,不会触发 HTTP POST。但是,如果我将代码更改为:
public async Task<HttpResponseMessage> SubmitMetric(<params>)
{
// build payload
using (var httpClient = new HttpClient())
{
return await httpClient.PostAsync(<params>);
}
}
Run Code Online (Sandbox Code Playgroud)
POST 按预期提交。为什么会发生这种情况?如果我并不真正关心 HTTP 响应,我该怎么办?我只想提交它并继续我的流程。我不应该能够在不await获取结果的情况下使用它吗?例如:
public void SubmitMetric(<params>)
{
// build payload
using (var httpClient = new HttpClient())
{
httpClient.PostAsync(<params>);
}
}
Run Code Online (Sandbox Code Playgroud) 我试图通过C#控制台应用程序使用REST API,并且我已经获得了web服务以返回JSON文件,其格式为:
{"status":200,"result":{"postcode":"SW1W0DT","quality":1,"eastings":528813,"northings":178953,"country":"England","nhs_ha":"London","longitude":-0.145828,"latitude":51.494853,"european_electoral_region":"London","primary_care_trust":"Westminster","region":"London","lsoa":"Westminster 023E","msoa":"Westminster 023","incode":"0DT","outcode":"SW1W","parliamentary_constituency":"Cities of London and Westminster","admin_district":"Westminster","parish":"Westminster, unparished area","admin_county":null,"admin_ward":"Warwick","ccg":"NHS Central London (Westminster)","nuts":"Westminster","codes":{"admin_district":"E09000033","admin_county":"E99999999","admin_ward":"E05000647","parish":"E43000236","parliamentary_constituency":"E14000639","ccg":"E38000031","nuts":"UKI32"}}}
Run Code Online (Sandbox Code Playgroud)
我创建了一个类AddressInfo如下:
public class AddressInfo {
public string postcode { get; set; }
public int quality { get; set; }
public int eastings { get; set; }
public int northings { get; set; }
public string country { get; set; }
public string nhs_ha { get; set; }
public string admin_county { get; set; }
public string admin_district { get; set; }
public string admin_ward …Run Code Online (Sandbox Code Playgroud) So I have an array of string like this in JS:
['07-01-16 06:55AM 57 100313_1_1_065215.bad',
'07-01-16 07:03AM 57 100313_1_1_070315.bad',
'07-01-16 07:26AM 61 100313_1_1_072315.bad',
...]
Run Code Online (Sandbox Code Playgroud)
and would like to become an array of objects so I can sort if by the two first fields like this:
{ date: '07-01-16',
hour: '07:03AM'
size: '67'
name: '100359_1_1_112700.bad'
}
{ name: '101105_1_1_200026.bad',
...}
Run Code Online (Sandbox Code Playgroud) public interface IAuthenticationService
{
Task<TurnaResponse> RegisterUser(User user);
Task<TurnaResponse> LoginUser(string email, string password);
Task<TurnaResponse> ResetPassword(string userId, string password);
Task<TurnaResponse> ForgotPassword(string email);
Task<TurnaResponse> ProcessSession(string userId);
bool IsUserAuthenticated();
}
public async Task<TurnaResponse> ProcessSession(string userId)
{
UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
{
Path = ApiConstants.ProcessSessionEndpoint
};
var query = System.Web.HttpUtility.ParseQueryString(builder.Query);
query["userId"] = userId;
builder.Query = query.ToString();
var result = await _genericRepository.GetAsync<TurnaResponse>(builder.ToString(), "");
result.Data = result.Data != null
? JsonConvert.DeserializeObject<User>(result.Data.ToString()) : result.Data;
_sessionResponse = (TurnaResponse)result;
return result;
}
Run Code Online (Sandbox Code Playgroud)
如何调用下面的 ProcessSession 方法来获取 IsAuthenticated 方法中返回 boolean 的响应对象? …
我在这个网站上尝试了这段代码,它工作正常并返回 60,因为它应该,但是当我尝试在 HTML 网页上运行它时,它首先返回 10,其他 2 个值将是 NaN,我不明白为什么发生此错误。我将不胜感激您的解决方案。
var numbers = [ 10, 20, 30 ] ;
numbers.reduce(function(sum , number){
return console.log( sum + number);
} , 0);Run Code Online (Sandbox Code Playgroud)
我有一个这样的条件:
List<HWSRunSession> session = new List<HWSRunSession>();
foreach (var item in fileInfo)
{
if(_db.HWSRunSessions.Where((x) => x.TransferredZipName == item.Name
&& DateTime.Now.Subtract(x.AddedDate).TotalDays >= _ExpirationDays) == null) {
bla bla...
}
}
Run Code Online (Sandbox Code Playgroud)
但是我想session使用“out”关键字将我在条件中检索到的列表保存到我的变量中。就像:
List<HWSRunSession> session = new List<HWSRunSession>();
foreach (var item in fileInfo)
{
if(_db.HWSRunSessions.Where((x) => x.TransferredZipName == item.Name
&& DateTime.Now.Subtract(x.AddedDate).TotalDays >= _ExpirationDays), out session == null) {
}
}
Run Code Online (Sandbox Code Playgroud)
这是可能的,如果可以,如何?
我有一个奇怪的问题,并尝试各种各样的事情来实现这一点.
我在我的Web API项目中有一个反向代理委托处理程序,它连接到内部资源,文件等的拦截请求,从我们的外部站点到我们DMZ内部的内部站点......
using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
namespace Resources.API
{
public class ProxyHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var routes = new[]{
"/api/videos",
"/api/documents"
};
// check whether we need to proxy this request
var passThrough = !routes.Any(route => request.RequestUri.LocalPath.StartsWith(route));
if (passThrough)
return await base.SendAsync(request, cancellationToken);
// got a hit forward the request to the proxy Web …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的JavaScript对象
server1:[38,1,2,7]
server2:[6,2,1,4
server3:[160,30,21,20]
Run Code Online (Sandbox Code Playgroud)
我想将此对象的元素插入这样的数组中
data1=[
[
{name:"Success", y:38},
{name:"Failure", y:1},
{name:"Aborted", y:2},
{name:"Unstable", y:7}
],
[
{name:"Success", y:6},
{name:"Failure", y:2},
{name:"Aborted", y:1},
{name:"Unstable", y:4}
],
[
{name:"Success", y:160},
{name:"Failure", y:30},
{name:"Aborted", y:21},
{name:"Unstable", y:20}
]
]
Run Code Online (Sandbox Code Playgroud)
JavaScript对象的键的第一个元素是成功,第二个元素是失败,第三个元素是不稳定的,第四个元素被中止,有什么办法可以做到这一点?任何帮助将不胜感激
我正在编写一个小程序来处理一些自动绘图。我正在使用一个控制台应用程序,它只需运行通过导出pdf绘图文件即可完成的代码。
由于我处于测试阶段,因此每次我想查看更改/添加的效果时都需要运行该程序。这意味着我很快就会打开很多控制台窗口,如果可能的话我想避免这种情况。
是否可以以编程方式关闭控制台窗口?
我已经尝试过Environment.Exit(),但它似乎没有做任何事情。
最小示例
static void Main(string[] args)
{
//Put any or no code here
}
Run Code Online (Sandbox Code Playgroud)
我希望控制台窗口在 Program.Main() 方法完成后关闭。相反,控制台要求“任意键”输入,并且在按下某个键后不会关闭。
控制台输出:
Press any key to continue...
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process Complete] (<- translated from danish)
Run Code Online (Sandbox Code Playgroud) c# ×6
javascript ×3
asp.net ×1
async-await ×1
asynchronous ×1
cors ×1
helper ×1
highcharts ×1
iis ×1
json ×1
macos ×1
out ×1
reduce ×1
xamarin ×1