On Sun, Nov 10, 2019 at 10:25 PM 洪嘉鴻 <max123...@gmail.com> wrote: > > Hello everyone: > I'm using golang with Win10. Now I'm trying to write a web browser. > The version of the golang which I am using is 1.12.9. Here is the problem > that I'm encountering: > Here is the code. The code couldn't run with "The Go Playground", while it > works with the "Visual Studio Code". > The results are what I want. However, there appears the message "http: > superfluous response.WriteHeader call from main.login" with line 34 and line > 37. > If I remove these two lines, the results won't serve the file. I have no idea > how to avoid the warning. > Here are the HTML files.
w.Write([]byte(result)) http.ServeFile(w, r, "form-3-2.html") The reason for that warning is these two lines. The first line writes some data to the response, which also forces the response writer to write HTTP response headers, which at this point are empty. Then, ServeFile sets some headers, and then writes those headers again, thinking this is the first time the response was written. But the headers are already written to the response, so the headers set by the ServeFile function is lost. That's the reason you get that warning. You should not set headers after you start writing the body. You seem to be trying to add a piece of text to an html file. Instead of doing it as you do, try using templates. > > Any help is appreciated. > Thank you very much! > Max > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/5e7457cf-119b-4be5-adc8-a94317fc837f%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMV2RqoqDGCz5nsUXXmOQpUCqBDodSJwN0Ws1vs5Jfxgn%2B4q7w%40mail.gmail.com.