标签: http-headers

Django:如何正确提供 mp3 文件

问题是我无法通过点击谷歌浏览器中的时间线来改变播放位置(它总是从头到尾播放)
如果Nginx 向客户端提供mp3 文件一切正常,我可以改变播放位置。


在我的脚本中,我以这种方式提供 mp3:

from django.core.servers.basehttp import FileWrapper
wrapper = FileWrapper(file( 'mp3file.mp3' ))
response = HttpResponse(wrapper, content_type='audio/mpeg')
response['Content-Length'] = os.path.getsize( 'mp3file.mp3' )
return response
Run Code Online (Sandbox Code Playgroud)

网址是: http://server/mp3/###.mp3

所以整个文件都给了客户端,但仍然无法更改播放位置。怎么了?

PS:不要使用任何专有的 sh*t 像 mp3 - 使用“.ogg”格式

python django mp3 http-headers

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

Apache Camel:查询参数与标头参数

我目前正在试用 Apache 骆驼(作为路由引擎)。我知道 Camel 支持多个 DSL,并且可以使用 Java (Java DSL) 或 Spring (Spring DSL) 进行配置。

问题:
我有以下 Spring DSL 配置。这个想法是,如果传入的请求具有名为“name”的标头参数,它将命中 when 子句,否则将请求路由到谷歌:

 <camel:route>
    <camel:from uri="servlet:///test" />
    <camel:choice>
        <camel:when>
            <camel:header>name</camel:header>
            <camel:transform>
                <camel:simple>Hello ${header.name} how are you?</camel:simple>
            </camel:transform>
        </camel:when>
        <camel:otherwise>
                <camel:to uri="http://www.google.com?bridgeEndpoint=true" />
        </camel:otherwise>
    </camel:choice>
</camel:route>
Run Code Online (Sandbox Code Playgroud)

我希望上述配置仅适用于 Header Param。但是,我注意到此配置甚至适用于查询参数,如以下请求所示:

http://localhost:8080/<war-context>/test?name=test
Run Code Online (Sandbox Code Playgroud)

有没有办法确保它仅适用于标题参数?

java apache-camel query-parameters http-headers spring-dsl

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

Nodejs使用'Access-Control-Allow-Origin'快速解决CORS问题

我正在尝试使用Angular 1,Nodejs和Express创建单页面应用程序.我正在使用Angular的$ http post功能发布请求,我将请求中的标头值传递给API端点.

我在Chrome中遇到错误消息:

XMLHttpRequest cannot load 
http://localhost:7878/EIAMIDSupportREST/EIAMIDSupport/updateEIAMID. The 
value of the 'Access-Control-Allow-Origin' header in the response must not 
be the wildcard '*' when the request's credentials mode is 'include'. Origin 
'http://localhost:3000' is therefore not allowed access. The credentials 
mode of requests initiated by the XMLHttpRequest is controlled by the 
withCredentials attribute.
Run Code Online (Sandbox Code Playgroud)

有了这个请求正文:

HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,PUT,POST,PATCH,DELETE
Access-Control-Allow-Headers: Content-Type
Allow: POST
Content-Type: text/html; charset=utf-8
Content-Length: 4
Date: Tue, 23 May 2017 23:32:15 GMT
Connection: …
Run Code Online (Sandbox Code Playgroud)

javascript http-headers node.js cors express

1
推荐指数
3
解决办法
5749
查看次数

在Swift 3中使用urlsession在http标头中发送承载令牌的问题

我正在使用urlsession在标头中发送承载令牌,但是我总是得到未经授权的结果。我已经看到服务器日志。我将身体放在那儿但没有头。

    let key = UserDefaults.standard.object(forKey: "loginKey") as! String
        print(key)
        let url = NSURL(string: baseurl+"***")

        let request = NSMutableURLRequest(url: url! as URL)

        request.httpMethod = "GET"

        request.addValue("Bearer " + key, forHTTPHeaderField: "Authorization")
        let task = URLSession.shared.dataTask(with: request as URLRequest) 
{(data,response,error) -> Void in

        if error != nil
        {
          print(error?.localizedDescription as Any)
                        return
        }

       do 
       {
          let json = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSDictionary

           print(json)
        }
      catch let error as NSError 
      {
         print(error.localizedDescription)
      }
    }
    task.resume()
Run Code Online (Sandbox Code Playgroud)

我也尝试过 request.setValue("Bearer " + key, …

json http-headers ios swift3 urlsession

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

更改基本HTTP身份验证领域和登录对话框消息

我想更改在实施基本身份验证期间弹出的消息。当前的默认消息是:

在此处输入图片说明

服务器需要用户名和密码。

对我来说更准确的是:

服务器需要电子邮件和密码。

我的问题是我找不到或不知道此消息在哪里设置以及是否可以更改。在线上的大多数问题都与基本身份验证实现有关,但这不是我的问题-我可以很好地实现它。我只需要为用户提供更准确的答复。

这是我使用echo强制验证窗口的方式:

c.Response().Header().Set(echo.HeaderWWWAuthenticate, `Basic realm="Your Email is your Username"`)
return echo.ErrUnauthorized
Run Code Online (Sandbox Code Playgroud)

注意:只有Firefox显示领域消息。Chrome和Opera都没有。

http http-authentication go http-headers

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

如何在没有任何浏览器扩展的情况下向浏览器请求添加标头

有时,需要为每个请求或从浏览器发出的特定请求添加特殊标头.执行此操作的常用方法是使用允许我们修改请求标头的浏览器扩展.有没有其他方法可以做到这一点,没有任何浏览器扩展?

PS - 我搜索过SO并没有找到一个实际建议或展示如何做我需要的帖子.

javascript browser firefox google-chrome http-headers

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

如何从发送到ASP.NET核心2.0 API控制器操作的请求中获取身份验证标头

我正在开发ASP.NET Core 2.0 RESTful API.我有一个场景,我需要使用HTTPGet方法在我的API控制器上调用操作,我需要提取用于调用另一个第三方API的用户名和密码值.用户名和密码与当前登录的用户标识无关,它们只是我想从我自己的API中发送到另一个API的值,但我不想只是在查询字符串中传递它们.

我可以在客户端中使用基本身份验证将用户名和密码添加到HttpRequestMessage身份验证标头中,然后在我的ASP.NET Core 2.0 API控制器操作中提取该标头吗?

我的客户端会在调用API的代码中出现类似的内容

    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, relativeUrl);
    var byteArray = new UTF8Encoding().GetBytes(string.Format($"username:password"));
    request.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
Run Code Online (Sandbox Code Playgroud)

而且,我的API控制器动作会启动这样的事情;

    [HttpGet()]
    public IActionResult GetUploadedFileList([FromQuery]int pageNumber, [FromQuery]int pageSize)
    {

        //Extract Authentication header values for username and password

    }
Run Code Online (Sandbox Code Playgroud)

任何人都可以提供如何从HTTPGet请求获取Authorization标头的示例

我意识到我可以使用HTTPPost [FromBody]轻松完成此操作,但我的用例要求此方法为HTTGet.

在此先感谢您的帮助.

编辑1 - 解决方案

由于此链接提供了一些提示,我能够让下面的代码工作.虽然这似乎很多工作,所以如果有人有更好或更清洁的解决方案,请发布你的例子.

    [HttpGet()]
    public IActionResult GetUploadedFiles([FromQuery]int pageNumber, [FromQuery]int pageSize)
    {

        string username = string.Empty;
        string password = string.Empty;

        if (Request.Headers.TryGetValue("Authorization", out StringValues authToken))
        {
            string authHeader = authToken.First(); …
Run Code Online (Sandbox Code Playgroud)

http-headers dotnet-httpclient asp.net-apicontroller asp.net-core-2.0

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

如何通过Angular 5传递标头数据?

这在Angular 4中有效。要使其在Angle 5中正常工作,我需要进行哪些更改?

 getGreeting(): Observable<string> {
    let headers = new Headers({ 'Authorization': 'Bearer ' + this.authenticationService.token });

  //cant find requestoptions
  let options = new RequestOptions({ headers: headers });

    return this.http.
        get(Constant.ApiRoot + Constant.GreetingService, options).
        map((response: Response) => response.text());
}
Run Code Online (Sandbox Code Playgroud)

http-headers angular angular-httpclient

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

HTTP :: Server :: Response#headers的`[] =`和`add`有什么区别?

我查看了两者的源代码[]=以及添加/操作头文件.add时的源代码.我仍然对两种添加/设置标题的方法感到困惑.这两种方法有什么区别?

http-headers crystal-lang

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

根据golang中的字节长度分割字符串

http请求标头的长度限制为4k。我想基于此限制拆分要包含在标题中的字符串。我应该[]byte(str)先分割后再使用string([]byte)每个分割部分转换回字符串吗?有没有更简单的方法可以做到这一点?

http go http-headers

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