小编net*_*ser的帖子

angular4 httpclient csrf不发送x-xsrf-token

在角度文档中,提到angular httpclient将自动XSRF-TOKENX-XSRF-TOKENpost请求的标题中发送cookie的值.文档链接

但它并没有为我发送标题.这是我的代码

Nodejs用于设置cookie的代码

router.get('/set-csrf',function(req,res,next){
    res.setHeader('Set-Cookie', "XSRF-TOKEN=abc;Path=/; HttpOnly; SameSite=Strict");    
    res.send();
  })
Run Code Online (Sandbox Code Playgroud)

我在app.module.ts中使用了httpclient

imports: [
  HttpClientModule
]
Run Code Online (Sandbox Code Playgroud)

**以上代码仅用于调试目的.我没有set-csrf端点.

但是当我发送帖子请求时它不会发送任何标题.我无法调试.

我已经在angular的github存储库中添加了这个问题.HttpXsrfInterceptor检查请求是GET还是HEAD,或者是否以http开头.如果为true,则跳过添加标题.

这是HttpXsrfInterceptor类中的代码

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    const lcUrl = req.url.toLowerCase();
    // Skip both non-mutating requests and absolute URLs.
    // Non-mutating requests don't require a token, and absolute URLs require special handling
    // anyway as the cookie set
    // on our origin is not the same as the token expected by another origin. …
Run Code Online (Sandbox Code Playgroud)

cookies csrf-protection x-xsrf-token angular

20
推荐指数
2
解决办法
1万
查看次数

选择然后再选择不同的值

我有3列questionid,replyiduserid.

我想选择所有questionid's from userid where userid is session[userid],然后选择questionid与它不同.

现在我把questionid属于$_SESSION['user_id']数组的所有属性(并从中删除重复项)然后再次传递另一个查询

foreach($array as $x)
{
$query="select questionid,replyid,userid from table where questionid=$x"
}
Run Code Online (Sandbox Code Playgroud)

但我认为上述步骤可以在查询本身完成(并且上述步骤也不起作用).我在下面试过,但它不起作用.如果我尝试传递此查询,则仍会出现重复值:

SELECT distinct(questionid),replyid,userid 
from table 
where userid=$_SESSION['user_id']
Run Code Online (Sandbox Code Playgroud)

那么查询应该是什么?

questionid,replyid,userid

8          ,2     ,45

8          ,3      ,45

9           ,8      ,41
Run Code Online (Sandbox Code Playgroud)

但作为 8,28,3在同一个网页(一个问题,两个答案),我想避免重复显示的问题...

所以我尝试了错误的方式,因为我采取了区别questionid,然后再次选择* from table where questionid是前一个.

但是,正如@ Mahmoud Gamal建议的那样

 SELECT distinct questionid, `answerid`, `userid`
 FROM `table` 
 WHERE  userid='$user' …
Run Code Online (Sandbox Code Playgroud)

php mysql sql arrays

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

收到错误"没有AlertIconAndTypesService的提供者!"

我正在使用带有角度4代码的清晰度模块.使用他们的警告框示例时,我收到上述错误

示例代码

<div class="alert alert-info">
    <div class="alert-items">
        <div class="alert-item">
            <div class="alert-icon-wrapper">
                <clr-icon class="alert-icon" shape="info-circle"></clr-icon>
            </div>
            <span class="alert-text">...</span>
            <div class="alert-actions">
                <a href="..." class="alert-action">Acknowledge</a>
                <a href="..." class="alert-action">Reset to green</a>
            </div>
        </div>
    </div>
    <button type="button" class="close" aria-label="Close">
        <clr-icon aria-hidden="true" shape="close"></clr-icon>
    </button>
</div>
Run Code Online (Sandbox Code Playgroud)

错误堆栈详细信息

错误错误:未捕获(在承诺中):错误:没有AlertIconAndTypesService的提供程序!错误:没有AlertIconAndTypesService的提供者!at injectError(core.es5.js:1169)atNisProviderError(core.es5.js:1207)at ReflectiveInjector_.webpackJsonp .../../../core/@angular/core.es5.js.ReflectiveInjector_.throwOrNull(core.es5.js:2649)在ReflectiveInjector .webpackJsonp .../../../core/@angular/core.es5.js.ReflectiveInjector_.getByKeyDefault(core.es5.js:2688)在ReflectiveInjector .webpackJsonp .../../../core/@angular/core.es5.js.ReflectiveInjector_.getByKey(core.es5.js:2620)at RefinInjector .webpackJsonp .../../../core/@angular/core.es5.js.ReflectiveInjector_.get(core.es5.js:2489)at resolveNgModuleDep( core.es5.js:9475)at NdModuleRef_.webpackJsonp .../../../core/@angular/core.es5.js.NgModuleRef_.get(core.es5.js:10557)at resolveDep(core. es5.js:11060)在injectClass(core.es5.js:10913)的injectError(core.es5.js:1169),在noProviderError(core.es5.js:1207),在ReflectiveInjector_.webpackJsonp .../../../core/@angular/core.es5.js.ReflectiveInjector_.throwOrNull(core.es5.js:2649)在ReflectiveInjector .webpackJsonp .../../../core/@angular/core.es5.js.ReflectiveInjector_.getByKeyDefault(core.es5.js:2688)在ReflectiveInjector .webpackJsonp .../../../core/@angular/core.es5.js.ReflectiveInjector_.getByKey(core.es5.js:2620)at RefinInjector .webpackJsonp .../../../core/@angular/core.es5.js.ReflectiveInjector_.get(core.es5.js:2489)at resolveNgModuleDep( core.es5.js:9475)at NdModuleRef_.webpackJsonp .../../../core/@angular/core.es5.js.NgModuleRef_.get(core.es5.js:10557)at resolveDep(core. es5.js:11060)在resolveClass(core.es5.js:10913)at resolvePromise(polyfills.bundle.js:3328)at …

angular vmware-clarity

4
推荐指数
2
解决办法
1766
查看次数