Duplicate headers received from server

前端 未结 5 476
难免孤独
难免孤独 2020-12-04 08:07

Duplicate headers received from server

The response from the server contained duplicate headers. This problem is generally the result of a misconfigured

相关标签:
5条回答
  • 2020-12-04 08:46

    Just put a pair of double quotes around your file name like this:

    this.Response.AddHeader("Content-disposition", $"attachment; filename=\"{outputFileName}\"");

    0 讨论(0)
  • 2020-12-04 08:49

    The server SHOULD put double quotes around the filename, as mentioned by @cusman and @Touko in their replies.

    For example:

    Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
    
    0 讨论(0)
  • 2020-12-04 09:00

    For me the issue was about a comma not in the filename but as below: -

    Response.ok(streamingOutput,MediaType.APPLICATION_OCTET_STREAM_TYPE).header("content-disposition", "attachment, filename=your_file_name").build();

    I accidentally put a comma after attachment. Got it resolved by replacing comma with a semicolon.

    0 讨论(0)
  • 2020-12-04 09:12

    This ones a little old but was high in the google ranking so I thought I would throw in the answer I found from Chrome, pdf display, Duplicate headers received from the server

    Basically my problem also was that the filename contained commas. Do a replace on commas to remove them and you should be fine. My function to make a valid filename is below.

        public static string MakeValidFileName(string name)
        {
            string invalidChars = Regex.Escape(new string(System.IO.Path.GetInvalidFileNameChars()));
            string invalidReStr = string.Format(@"[{0}]+", invalidChars);
            string replace = Regex.Replace(name, invalidReStr, "_").Replace(";", "").Replace(",", "");
            return replace;
        }
    
    0 讨论(0)
  • 2020-12-04 09:12

    Double quotes around the filename in the header is the standard per MDN web docs. Omitting the quotes creates multiple opportunities for problems arising from characters in the filename.

    0 讨论(0)
提交回复
热议问题