Panic in Package "net/http/httptest"

Hi all!
I had got Panic when I passed separated string like this “foo boo” to target.

https://play.golang.org/p/bs6sF09Eboc

You pass an illigal argument to NewRequest. It requires this:

The target is the RFC 7230 “request-target”: it may be either a path or an absolute URL.

This

"http://example.com/foo boo"

is neither a path nor an absolute URL. If you want the blank to be part of the path, use url.PathEscape to escape it:

url.PathEscape("http://example.com/foo boo")

see Go Playground - The Go Programming Language

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.