标签: httpresponse

http响应状态代码402和403之间的差异

朋友和其他用户,

我们有402和403 http响应代码.但是,402保留供将来使用.

这两者之间的区别是什么(或将会是什么).未收到的付款应该等于未授权,不是吗?

编辑:我想知道"当我们已经有403"角度时"为什么需要402"的答案.

http httpresponse http-status-codes http-status-code-403

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

导出具有正确编码的文件

我不明白这里缺少什么.我试图用csv格式导出一个带有扩展ASCII字符的文件,ÿ或者ü我得到的是
我是否需要在响应中指定其他内容?

Encoding encoding = Encoding.UTF8;

//ToCSV writes the string correctly
var bytes = encoding.GetBytes("write ÿ or ü please");
MemoryStream stream = new MemoryStream(bytes);

StreamReader reader = new StreamReader(stream);
//TextWriter tw = new TextWriter();
Response.Clear();
Response.Buffer = true;

Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.csv", fileName));
Response.Charset = encoding.EncodingName;
Response.ContentType = "application/text";
Response.Output.Write(reader.ReadToEnd());
Response.Flush();
Response.End();
Run Code Online (Sandbox Code Playgroud)

c# encoding file httpresponse

8
推荐指数
2
解决办法
3万
查看次数

如何存储可能包含二进制数据的Http响应?

正如我在上一个问题中描述的那样,我有一个编写代理服务器的任务.它现在部分工作,但我仍然有处理gzip信息的问题.我将HttpResponse存储在一个字符串中,看起来我不能用gzip压缩内容.但是,标题是我需要解析的文本,它们都来自同一个文本InputStream.我的问题是,为了正确处理二进制响应,我还需要做什么,同时仍然将头解析为字符串?

>>在查看代码之前,请参阅下面的编辑.

这是Response类实现:

public class Response {
    private String fullResponse = "";
    private BufferedReader reader;
    private boolean busy = true;
    private int responseCode;
    private CacheControl cacheControl;

    public Response(String input) {
        this(new ByteArrayInputStream(input.getBytes()));
    }

    public Response(InputStream input) {
        reader = new BufferedReader(new InputStreamReader(input));
        try {
            while (!reader.ready());//wait for initialization.

            String line;
            while ((line = reader.readLine()) != null) {
                fullResponse += "\r\n" + line;

                if (HttpPatterns.RESPONSE_CODE.matches(line)) {
                    responseCode = (Integer) HttpPatterns.RESPONSE_CODE.process(line);
                } else if …
Run Code Online (Sandbox Code Playgroud)

java encoding http httpresponse

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

有关从服务器发送响应时的浏览器行为的问题

场景:

  • 浏览器向服务器提交HTTP请求.
  • 用户同时点击书签或页面上的另一个链接,从而产生对服务器的新请求.
  • 服务器现在发回两个HTTP响应(或浏览器从两个服务器获取响应).

浏览器如何确定实际处理哪些响应?

我知道会发生什么 - 我想知道为什么.任何解释这一点的参考或网站也将非常感激.

谢谢,

维韦克.

编辑:询问后看到这个类似的问题.如果合适,请合并/删除.

browser httpresponse httprequest

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

覆盖HTTP响应中的"缓存控制"值

我有一个网页,当我访问材料时返回以下标题:

HTTP/1.1 200 OK
Date: Sat, 29 Jun 2013 15:57:25 GMT
Server: Apache
Content-Length: 2247515
Cache-Control: no-cache, no-store, must-revalidate, max-age=-1
Pragma: no-cache, no-store
Expires: -1
Connection: close
Run Code Online (Sandbox Code Playgroud)

使用chrome扩展,我想修改它,response header以便实际缓存材料而不是浪费带宽.

我有以下示例代码:

chrome.webRequest.onHeadersReceived.addListener(function(details) 
    {
        // Delete the required elements
        removeHeader(details.responseHeaders, 'pragma');
        removeHeader(details.responseHeaders, 'expires');

        // Modify cache-control
        updateHeader(details.responseHeaders, 'cache-control', 'max-age=3600;')

        console.log(details.url);
        console.log(details.responseHeaders);

        return{responseHeaders: details.responseHeaders};
    },
    {urls: ["<all_urls>"]}, ['blocking', 'responseHeaders']
);
Run Code Online (Sandbox Code Playgroud)

这正确地将标题修改为这样的东西(基于console.log()输出):

HTTP/1.1 200 OK
Date: Sat, 29 Jun 2013 15:57:25 GMT
Server: Apache
Content-Length: 2247515
Cache-Control: max-age=3600
Connection: close
Run Code Online (Sandbox Code Playgroud)

但基于我试图检查的所有内容,我无法看到任何证据确实发生了这种情况:

  1. 在 …

google-chrome httpresponse cache-control http-headers google-chrome-extension

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

Django:在现有的html页面上返回StreamingHttpResponse

由于每个问题最好只有一个问题,如果与我同一项目的另一部分相似,请耐心等待.

情况:

我在html上有一个表单,我可以在其中设置一个数字,当它被提交时,调用views.stream_response将值传递给stream.py并返回StreamingHttpResponse并显示"虚拟"空白浏览器页面(/ stream_response /),其中我可以每秒钟看到一个渐进的数字m:

   1
   2
   3
   ..
   m
Run Code Online (Sandbox Code Playgroud)

stream.py

import time

def streamx(m):
    lista = []
    x=0
    while len(lista) < m:      
        x = x + 1
        time.sleep(1)
        lista.append(x)
        yield "<div>%s</div>\n" % x 
        print(lista[-1])    
    return (x)
Run Code Online (Sandbox Code Playgroud)

--- UPDATE ---

views.py

def stream_response(request):   
    test = InputNumeroForm()   
    if request.method == 'POST':
        test = InputNumeroForm(data=request.POST)
        if test.is_valid():
            m = test.cleaned_data['numero']     
            print (test)      
            print("m = ", m) 
            #resp = StreamingHttpResponse(stream_response_generator(m))
            resp …
Run Code Online (Sandbox Code Playgroud)

html django streaming httpresponse django-views

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

使用Python中的请求库测量HTTP响应时间.我做得对吗?

我试图从Web应用程序中引发HTTP响应的人为延迟(这是一种用于执行盲SQL注入的技术).如果从浏览器发送以下HTTP请求,则Web服务器的响应在3秒后返回(由sleep(3)引起):

http://192.168.2.15/sqli-labs/Less-9/?id=1'+and+if+(ascii(substr(database(),+1,+1))=115,sleep(3),null)+--+
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用请求库在Python 2.7中执行相同的操作.我的代码是:

import requests

payload = {"id": "1' and if (ascii(substr(database(), 1, 1))=115,sleep(3),null) --+"}
r = requests.get('http://192.168.2.15/sqli-labs/Less-9', params=payload)
roundtrip = r.elapsed.total_seconds()
print roundtrip
Run Code Online (Sandbox Code Playgroud)

我预计往返时间为3秒,但我得到的值为0.001371,0.001616,0.002228等.我没有正确使用经过的属性吗?

elapsed httpresponse roundtrip python-2.7 python-requests

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

使用laravel 5发送重定向和设置cookie

我编写了这段代码,在客户端的浏览器中设置了一个cookie,之后必须将客户端重定向到"home"路由,

$response = new Response();
$response->withCookie(cookie()->forever('language', $language));
$response->header('Location' , url('/home')) ;
return $response ;
Run Code Online (Sandbox Code Playgroud)

客户端收到这些标题但客户端不会请求"主页"路由 在此输入图像描述

我该如何做,设置cookie并重定向用户?

php redirect httpresponse laravel

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

如何在Angular JS中显示作为字节数组接收的图像

我有一个服务器端应用程序将返回一个图像.这些是响应标头:

Content-Disposition: attachment; filename=8822a009-944e-43f4-999b-d297198d302a;1.0_low-res
Content-Length: 502343
Content-Type: image/png
Date: Mon, 03 Aug 2015 19:13:39 GMT
Server: Apache-Coyote/1.1
Run Code Online (Sandbox Code Playgroud)

在角度,我需要显示图像.在获取图像时,我使用angularJS $http来调用服务器并将结果放在范围内,但我从未达到成功函数$http.从邮递员执行此调用会正常返回图像.我很想知道如何让Angular显示图像.

这是我显示图像的方式:

<img ng-src={{image}} />
Run Code Online (Sandbox Code Playgroud)

这是从服务器获取图像的调用:

$http.get(url, {responseType: "arraybuffer"})
    .success(function(data) {
        $scope.image= data;
    }
)
Run Code Online (Sandbox Code Playgroud)

javascript image bytearray httpresponse angularjs

8
推荐指数
2
解决办法
3万
查看次数

当响应超过8kb时,为什么golang http服务器因"断管"而失败?

下面我有在那里,如果你调用一个例子Web服务器curl localhost:3000 -v,然后^C(取消)立即(在1秒内),它会报告write tcp 127.0.0.1:3000->127.0.0.1:XXXXX: write: broken pipe.

package main

import (
    "fmt"
    "net/http"
    "time"
)

func main() {
    log.Fatal(http.ListenAndServe(":3000", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
            time.Sleep(1 * time.Second)

            // Why 8061 bytes? Because the response header on my computer
            // is 132 bytes, adding up the entire response to 8193 (1 byte 
            // over 8kb)
            if _, err := w.Write(make([]byte, 8061)); err != nil {
                    fmt.Println(err)
                    return
            }   
    })))
}
Run Code Online (Sandbox Code Playgroud)

根据我的调试,我得出结论,只有当整个响应写入超过8192字节(或8kb)时才会发生这种情况.如果我的整个响应写入少于8192,broken pipe则不会返回错误. …

curl http httpresponse go

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