multiple response.WriteHeader calls in really simple example?

后端 未结 6 512
慢半拍i
慢半拍i 2020-12-10 10:43

I have the most basic net/http program that I\'m using to learn the namespace in Go:

package main

import (
    \"fmt\"
    \"log\"
    \"net/http\"
)

func          


        
6条回答
  •  暖寄归人
    2020-12-10 11:14

    You already received a correct answer which addresses your problem, I will give some information about the general case (such error appears often).

    From the documentation, you see that WriteHeader sends an http status code and you can't send more than 1 status code. If you Write anything this is equivalent to sending 200 status code and then writing things.

    So the message that you see appears if you either user w.WriteHeader more than once explicitly or uses w.Write before w.WriteHeader.

提交回复
热议问题