标签: http-headers

Nginx不接受字节范围

我正在使用nginx从文件系统提供视频。我想启用范围请求。

目前,这是我文件的返回结果

curl -I fileurl
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 29 Mar 2014 06:41:41 GMT
Content-Type: video/mp4
Content-Length: 15603963
Last-Modified: Sat, 04 Jan 2014 15:02:26 GMT
Connection: keep-alive
Keep-Alive: timeout=300
Accept-Ranges: bytes
Run Code Online (Sandbox Code Playgroud)

但是,如果我发送curl --header“ Range:bytes = 0-50” fileurl

整个文件已下载。

这是nginx配置中的服务器:

server {
            listen 80;
            server_name myserver;
            error_log logs/myserver.error.log;
            access_log logs/myserver.access.log;

            root /srv/myserver;

            #add_header Accept-Ranges;
            add_header Accept-Ranges bytes;
    }
Run Code Online (Sandbox Code Playgroud)

我还需要启用其他功能吗?如何允许文件的范围请求?

http nginx video-streaming http-headers html5-video

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

触发文件下载时,我有哪些设置Accept标头的选项?

我有一个路由/reports/foo-report/rendered/将返回文件下载(使用Content-Disposition标题).根据REST的建议,报告是作为pdf还是powerpoint返回,取决于请求的Accept标头.

触发文件下载时,我可以选择设置此标头?我显然不能使用XmlHttpRequest,链接或表格.我目前正在使用令人敬畏的jquery.fileDownload,但它似乎也不支持这个.

有没有办法在浏览器中以适当的RESTy方式做到这一点?

html browser rest download http-headers

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

究竟要把防伪手表放在哪里

我有一个布局页面,其中包含一个带有AntiForgeryToken的表单

using (Html.BeginForm(action, "Account", new { ReturnUrl = returnUrl }, FormMethod.Post, new { Id = "xcrf-form" }))
Run Code Online (Sandbox Code Playgroud)

这会生成一个隐藏字段

<input name="__RequestVerificationToken" type="hidden" value="p43bTJU6xjctQ-ETI7T0e_0lJX4UsbTz_IUjQjWddsu29Nx_UE5rcdOONiDhFcdjan88ngBe5_ZQbHTBieB2vVXgNJGNmfQpOm5ATPbifYE1">
Run Code Online (Sandbox Code Playgroud)

在我的角度视图中(在布局页面中加载div,我这样做

<form class="form" role="form" ng-submit="postReview()">
Run Code Online (Sandbox Code Playgroud)

我的postReview()代码如下

$scope.postReview = function () {
    var token = $('[name=__RequestVerificationToken]').val();

    var config = {
        headers: {
            "Content-Type": "multipart/form-data",
            // the following when uncommented does not work either
            //'RequestVerificationToken' : token
            //"X-XSRF-TOKEN" : token
        }
    }

    // tried the following, since my other MVC controllers (non-angular) send the token as part of form data, …
Run Code Online (Sandbox Code Playgroud)

javascript asp.net-mvc http http-headers angularjs

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

来自脚本的格式错误的标题 错误的标头= 1:index.php

我有一个现在已有几年的网站,它基本上提供下载.

无论如何,因为移动服务器的人无法下载文件,因为它现在给出错误500错误,并且在日志文件中它带来了这个错误:

来自脚本的格式错误的标题 错误的标头= 1:index.php

我能看到的与此相关的唯一代码是:

// Echo $productOptionDetails->file;                
$file = DOWNLOAD_FOLDER. '/'. $productOptionDetailEntity->file;

    if (file_exists($file)) {

        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file) + 1);
        ob_clean();
        flush();
        readfile($file);
        exit;
    }
Run Code Online (Sandbox Code Playgroud)

现在如果我输出:

// Echo $productOptionDetails->file;                
$file = DOWNLOAD_FOLDER. '/'. $productOptionDetailEntity->file;

if (file_exists($file)) {
   readfile($file);
   exit;
}
Run Code Online (Sandbox Code Playgroud)

它会输出大量加密文本,因此它显然可以阅读.

我读过的是标题不正确但在阅读了php.net以及其他网站中的内容后,这看起来很好.

任何人都可以大声说出我为什么会收到这些错误?

谢谢

php malformed http-headers

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

是否有用于移动http请求的标准标头,用于指定设备类型,操作系统版本,应用程序版本等?

我正在为我的移动客户端创建一个JSON API,想知道是否已经有像User-Agent这样的标准来发送诸如

  • 设备类型
  • 设备操作系统
  • 应用程式版本

或我的服务器想知道的有关客户端设备的任何其他信息...

由于移动用途已变得越来越流行,因此,如果有某种标准,这似乎是合理的。

  1. 我是否应该要求我的客户在User-Agent标头中发送所有这些信息(即使浏览器未发送请求)?
  2. 我是否应该为这些类型的字段创建自定义标题,并为它们添加前缀X-MyApp-...?

我知道我可以选择使用我喜欢的任何方法,因为它是我的api,我可以决定自己想要什么,但是我很好奇在这方面是否有任何行业标准。

谢谢

api android http http-headers ios

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

请求 - 获取内容类型/大小而不获取整个页面/内容

我有一个简单的网站爬虫,它工作正常,但有时它因为大型内容,如ISO图像,.exe文件和其他大的东西而卡住.使用文件扩展名猜测内容类型可能不是最好的主意.

是否可以在不获取整个内容/页面的情况下获取内容类型和内容长度/大小?

这是我的代码:

requests.adapters.DEFAULT_RETRIES = 2
url = url.decode('utf8', 'ignore')
urlData = urlparse.urlparse(url)
urlDomain = urlData.netloc
session = requests.Session()
customHeaders = {}
if maxRedirects == None:
    session.max_redirects = self.maxRedirects
else:
    session.max_redirects = maxRedirects
self.currentUserAgent = self.userAgents[random.randrange(len(self.userAgents))]
customHeaders['User-agent'] = self.currentUserAgent
try:
    response = session.get(url, timeout=self.pageOpenTimeout, headers=customHeaders)
    currentUrl = response.url
    currentUrlData = urlparse.urlparse(currentUrl)
    currentUrlDomain = currentUrlData.netloc
    domainWWW = 'www.' + str(urlDomain)
    headers = response.headers
    contentType = str(headers['content-type'])
except:
    logging.basicConfig(level=logging.DEBUG, filename=self.exceptionsFile)
    logging.exception("Get page exception:")
    response = None
Run Code Online (Sandbox Code Playgroud)

python content-type http-headers python-requests

5
推荐指数
3
解决办法
8606
查看次数

angular.js $ resources设置授权标头

JS

我正在尝试做的是为服务器提供REST API REQUEST.

请求应为'GET'方法并包含'Authorization'标头.

我的工厂代码与REST服务器通信就像这样'use strict';

angular.module('mabidualApp')
  .factory('User', function ($resource, config) {

    return $resource(config.API+':url/:id', {
        url: '@url', id: '@id'
    }, { //parameters default
      auth: {
        method: 'POST',
        params: {
            url: "token",
        }
    },
      get: {
        method: 'GET',
        headers:{'Authorization':'Bearer oLDMYrJD0Qg15Nhv7N-H6w'} ,
        params: {
          url:"users",
          id:'me'
        }
      }
});
Run Code Online (Sandbox Code Playgroud)

最合适的问题在这里

headers:{'Authorization':'Bearer oLDMYrJD0Qg15Nhv7N-H6w'} ,
Run Code Online (Sandbox Code Playgroud)

如果我添加标题,方法将更改为"OPTIONS"而不是"GET".我发现它是关于CORS预检的东西,但我无法弄清楚如何禁用它..

所以我试着在app.js中更改我的配置

  .config(function($locationProvider, $routeProvider, $httpProvider) {
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
    $httpProvider.defaults.headers.get['Authorization'] ='Bearer oLDMYrJD0Qg15Nhv7N-H6w';
Run Code Online (Sandbox Code Playgroud)

第二个问题在这里

$httpProvider.defaults.headers.get['Authorization'] ='Bearer oLDMYrJD0Qg15Nhv7N-H6w';
Run Code Online (Sandbox Code Playgroud)

它会出现以下错误.

Cannot set property 'Authorization' of undefined
Run Code Online (Sandbox Code Playgroud)

是否有任何解决方案可以使用'授权'标题发送''GET'请求?谢谢

http-headers angularjs preflight

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

设置标题(content-type:image/<ANY IMG FORMAT>)

处理我显示的图像的php文件只允许一种图像格式,.jpg,.png,.bmp等,但不是全部.imageName存储数据库中存储的图像的文件名,包括其格式.这是我的代码,到目前为止它还没有工作,我不确定是否允许这样做.你能帮我解决一下吗?

$con = mysqli_connect("localhost","root","","tickets");
$ticket = 109;
$result = mysqli_query($con,"SELECT image, imageName FROM tix WHERE tktNum=$ticket");


while($row = mysqli_fetch_array($result))
{
    $image = $row['image'];
    $imageName = $row['imageName'];
    $format = substr( $imageName, -3 ); //gets the last 3 chars of the file name, ex: "photo1.png" gets the ".png" part
    header('content-type: image/' . $format);
}
Run Code Online (Sandbox Code Playgroud)

php substr http-headers

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

在C中使用libcurl和liboauth发布推文

我正在尝试使用以下代码向Twitter发布推文,但不断收到错误"无法验证您","代码":32":

 curl_global_init(CURL_GLOBAL_ALL);
 CURL *curl = curl_easy_init();

 char *signedurl = malloc(sizeof(char) * 1024); /* Not how it will be, but works in this example. */

 char *url = "https://api.twitter.com/1.1/statuses/update.json";
 signedurl = oauth_sign_url2(url, NULL, OA_HMAC, "POST", consumer_key, consumer_secret, user_token, user_secret);
 char *status = "status=test";

 curl_easy_setopt(curl, CURLOPT_URL, signedurl); /* URL we're connecting to, after being signed by oauthlib */
 curl_easy_setopt(curl, CURLOPT_USERAGENT, "dummy-string"); /* Not the actual string, just a dummy for this example */
 curl_easy_setopt(curl, CURLOPT_POST, 1);
 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, status);
 //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); …
Run Code Online (Sandbox Code Playgroud)

c twitter libcurl http-headers twitter-oauth

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

HTTP Server如何响应分块编码的HEAD请求

我有一个问题,当HEAD被发送到资源并且服务器决定执行分块编码时,HTTP Server响应如何?

如果服务器总是希望对特定资源上的GET执行分块编码,因为它在生成响应时不知道确切的内容长度,那么当在同一资源上发送HEAD时,服务器应该如何表现.

http httpresponse rfc2616 http-headers

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