first path segment in URL cannot contain colon
来源:互联网 发布:淘宝花种子哪家好 编辑:程序博客网 时间:2024/06/08 12:52
一:问题
func main(){ url,err:= url.Parse("127.0.0.1:8080") if err!=nil{ fmt.Println(err) } fmt.Println(url.Host,url.Port())}
使用url.Parse()解析host是ip的url时(eg:127.0.0.1:8080),出现:first path segment in URL cannot contain colon
二:问题原因
报错的原因:url.Parse()里面调用的func parse(rawurl string, viaRequest bool) (*URL, error)
这个函数报错
func parse(rawurl string, viaRequest bool) (*URL, error) {//.......if !strings.HasPrefix(rest, "/") { if url.Scheme != "" { // We consider rootless paths per RFC 3986 as opaque. url.Opaque = rest return url, nil } if viaRequest { return nil, errors.New("invalid URI for request") } // Avoid confusion with malformed schemes, like cache_object:foo/bar. // See golang.org/issue/16822. // // RFC 3986, §3.3: // In addition, a URI reference (Section 4.1) may be a relative-path reference, // in which case the first path segment cannot contain a colon (":") character. //报错位置 colon := strings.Index(rest, ":") slash := strings.Index(rest, "/") if colon >= 0 && (slash < 0 || colon < slash) { // First path segment has colon. Not allowed in relative URL. return nil, errors.New("first path segment in URL cannot contain colon") } } //............
三.处理方法
在func parse(rawurl string, viaRequest bool) (*URL, error)中:
if (url.Scheme != "" || !viaRequest && !strings.HasPrefix(rest, "///")) && strings.HasPrefix(rest, "//") { var authority string authority, rest = split(rest[2:], "/", false) url.User, url.Host, err = parseAuthority(authority) if err != nil { return nil, err } }
看到这个部分,可以在127.0.0.1:8080前面加”//”解决(eg://127.0.0.1:8080)
四:补充
关于//host:port
(this format is called the “network-path reference” from RFC 3986, section 4.2)
可以参考:https://stackoverflow.com/questions/3583103/network-path-reference-uri-scheme-relative-urls
阅读全文
0 0
- first path segment in URL cannot contain colon
- NDK path cannot contain space!
- Path used in ActionScript-Url,Absolute Url,Relative Url
- 配置NDK环境变量遇到ndk path cannot contain any spaces错误的解决办法
- BUILD_FINGERPRINT cannot contain spaces
- Cannot find module with tag 'libjpeg' in import path
- WebDriverException: Cannot find firefox binary in PATH."的解决方法
- webstorm提示"Cannot detect android SDK in path"
- Cannot find module with tag 'cpufeatures' in import path
- WebDriverException: Cannot find firefox binary in PATH."的解决方法
- contains dots but no replacement was configured!Make sure map keys don't contain dots in the first p
- Constraint must contain a first layout item
- First In
- Cannot find Velocity template for URL : Did you specify the correct resource loader path?
- 报错处理java.lang.IllegalStateException: Cannot map handler 'operatorController' to URL path [/update]:
- Cannot map handler 'algorithmPlatform' to URL path [/execute.do]: There is already handler of type
- class path resource [logConfig.xml] cannot be resolved to URL because it does not exist
- class path resource [setting.xml] cannot be resolved to URL because it does not exist
- SSH远程连接LINUX
- 前端优化带来的思考,浅谈前端工程化
- vue组件-文件树
- 自定义ViewGroup(二)
- Vue-router之初体验(持续更新)
- first path segment in URL cannot contain colon
- 在cmd中报错:java找不到或无法加载主类
- HaoSQL_好用的SQL等数据库一键包发布!
- 【递归入门】组合+判断素数
- Qt5.9 在windows下静态编译
- Scala.for.the.Impatient.2nd.Edition.2016.12.pdf 英文原版 免费下载
- SpringBoot项目集成RabbitMq
- esayui查询信息单选按钮回显选中
- IT领域的721定律