我已经按照npm包文档的建议写了一个Axios POST请求,比如:

var data = {
    'key1': 'val1',
    'key2': 'val2'
}
axios.post(Helper.getUserAPI(), data)       
.then((response) => {
    dispatch({type: FOUND_USER, data: response.data[0]})
})
.catch((error) => {
    dispatch({type: ERROR_FINDING_USER})
})

它工作,但现在我已经修改了我的后端API接受头文件。

内容类型:“application / json” 授权:“JWT fefege…”

现在,这个请求在Postman上工作得很好,但在编写axios调用时,我遵循了这个链接,但不能完全使其工作。

我经常得到400坏请求错误。

这是我修改后的请求:

axios.post(Helper.getUserAPI(), {
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'JWT fefege...'
    },
    data
})      
.then((response) => {
    dispatch({type: FOUND_USER, data: response.data[0]})
})
.catch((error) => {
    dispatch({type: ERROR_FINDING_USER})
})

我正在用React和Redux构建一个前端应用程序,我正在使用axios来执行我的请求。我想访问响应头中的所有字段。在我的浏览器中,我可以检查标题,我可以看到我需要的所有字段都是存在的(如令牌,uid等…),但当我调用

const request = axios.post(`${ROOT_URL}/auth/sign_in`, props);
request.then((response)=>{
  console.log(response.headers);
});

我只是

Object {content-type: "application/json; charset=utf-8", cache-control: "max-age=0, private, must-revalidate"}

这里我的浏览器网络选项卡,正如你可以看到的所有其他领域都存在。

最好成绩。

使用Flask,我如何读取HTTP头?我想检查客户端发送的授权头。

我想知道JWT令牌最合适的授权HTTP头类型是什么。

最受欢迎的类型之一可能是Basic。例如:

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

它处理两个参数,如登录名和密码。所以它与JWT令牌无关。

此外,我还听说过承载型,例如:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ

然而,我不知道它的意思。它和熊有关吗?

在HTTP授权报头中使用JWT令牌有特殊的方法吗?我们是应该使用承载者,还是应该简化使用:

Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ

谢谢。

编辑:

或者,只是一个JWT HTTP报头:

JWT: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ

看看下面两种方法:

public static void foo() {
    try {
        foo();
    } finally {
        foo();
    }
}

public static void bar() {
    bar();
}

运行bar()显然会导致StackOverflowError,但运行foo()不会(程序似乎无限期地运行)。为什么呢?

我遇到了一个问题,将存储在数据库中的文件发送回ASP中的用户。净MVC。我想要的是一个列出两个链接的视图,一个用于查看文件并让发送到浏览器的mimetype决定如何处理它,另一个用于强制下载。

如果我选择查看一个名为SomeRandomFile.bak的文件,而浏览器没有相关的程序来打开这种类型的文件,那么它默认为下载行为就没有问题。但是,如果我选择查看名为SomeRandomFile.pdf或SomeRandomFile.jpg的文件,我希望该文件直接打开。但是我还想在旁边保留一个下载链接,这样无论文件类型如何,我都可以强制下载提示。这有道理吗?

我已经尝试了FileStreamResult,它适用于大多数文件,它的构造函数默认不接受文件名,因此未知文件被分配一个基于URL的文件名(不知道扩展名基于内容类型)。如果我强制指定文件名,浏览器就不能直接打开文件,只能得到下载提示。有人遇到过这种情况吗?

这些是我目前为止尝试过的例子。

//Gives me a download prompt.
return File(document.Data, document.ContentType, document.Name);

//Opens if it is a known extension type, downloads otherwise (download has bogus name and missing extension)
return new FileStreamResult(new MemoryStream(document.Data), document.ContentType);

//Gives me a download prompt (lose the ability to open by default if known type)
return new FileStreamResult(new MemoryStream(document.Data), document.ContentType) {FileDownloadName = document.Name};

有什么建议吗?


UPDATE: This questions seems to strike a chord with a lot of people, so I thought I'd post an update. The warning on the accepted answer below that was added by Oskar regarding international characters is completely valid, and I've hit it a few times due to using the ContentDisposition class. I've since updated my implementation to fix this. While the code below is from my most recent incarnation of this problem in an ASP.NET Core (Full Framework) app, it should work with minimal changes in an older MVC application as well since I'm using the System.Net.Http.Headers.ContentDispositionHeaderValue class.

using System.Net.Http.Headers;

public IActionResult Download()
{
    Document document = ... //Obtain document from database context

    //"attachment" means always prompt the user to download
    //"inline" means let the browser try and handle it
    var cd = new ContentDispositionHeaderValue("attachment")
    {
        FileNameStar = document.FileName
    };
    Response.Headers.Add(HeaderNames.ContentDisposition, cd.ToString());

    return File(document.Data, document.ContentType);
}

// an entity class for the document in my database 
public class Document
{
    public string FileName { get; set; }
    public string ContentType { get; set; }
    public byte[] Data { get; set; }
    //Other properties left out for brevity
}

我在开发人员控制台得到一堆错误:

拒绝计算字符串 拒绝执行内联脚本,因为它违反了以下内容安全策略指示 拒绝加载脚本 拒绝加载样式表

这是怎么回事?内容安全策略(CSP)如何工作?如何使用内容安全策略HTTP报头?

具体来说,如何……

...允许多个信息源? ...使用不同的指令? ...使用多个指令? ...处理港口? ...处理不同的协议? ...允许文件://协议? ...使用内联样式,脚本和标签<style>和<script>? ...允许eval () ?

最后:

“自我”到底是什么意思?

您如何确定地检测用户是否在浏览器中按下了后退按钮?

如何使用#URL系统在单页web应用程序中强制使用页面内返回按钮?

为什么浏览器的后退按钮不触发它们自己的事件!?

当我试图连接到SQL Server时,我得到这个错误。

Microsoft SQL Server错误:18456

有人能告诉我错误码是什么意思吗?

我应该如何阅读任何头在PHP?

例如自定义报头:X-Requested-With。