当前位置: 首页 > news >正文

开发一栋楼需要多少钱南宁seo排名收费

开发一栋楼需要多少钱,南宁seo排名收费,建立网站流程,外包小程序开发技巧背景 某日使用okhttp设置代理并发送爬虫请求时,发现部分url请求没有走代理直接和目标url建立了连接,伪代码如下。初始化okhttpClient时设置了proxySelecter代理,但是调用okhttpClient.newCall请求时并没用调用proxySelecter.select函数获取代…

背景

某日使用okhttp设置代理并发送爬虫请求时,发现部分url请求没有走代理直接和目标url建立了连接,伪代码如下。初始化okhttpClient时设置了proxySelecter代理,但是调用okhttpClient.newCall请求时并没用调用proxySelecter.select函数获取代理,日志也没有打印。

    public void call(String url) {ProxySelector proxySelector = new ProxySelector() {@Overridepublic List<Proxy> select(URI uri) {log.info("run into proxy");Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 80));return Collections.singletonList(proxy);}@Overridepublic void connectFailed(URI uri, SocketAddress sa, IOException ioe) {return;}};OkHttpClient client = new OkHttpClient.Builder().proxySelector(proxySelector).build();okhttp3.Request request = new Request.Builder().url(url).build();client.newCall(request);}

okHttp & 代理

Android | 彻底理解 OkHttp 代理与路由

为什么没走代理

okhttp选择proxy时,现将传入的url传换为uri,如果uri的host为空,okhttp选择直连url,放弃走代理

okhttp3.internal.connection.RouteSelector
  private fun resetNextProxy(url: HttpUrl, proxy: Proxy?) {fun selectProxies(): List<Proxy> {// If the user specifies a proxy, try that and only that.if (proxy != null) return listOf(proxy)// If the URI lacks a host (as in "http://</"), don't call the ProxySelector.val uri = url.toUri()//此处,如果host解析出来为null。放弃走设置的代理if (uri.host == null) return immutableListOf(Proxy.NO_PROXY)// Try each of the ProxySelector choices until one connection succeeds.val proxiesOrNull = address.proxySelector.select(uri)if (proxiesOrNull.isNullOrEmpty()) return immutableListOf(Proxy.NO_PROXY)return proxiesOrNull.toImmutableList()}eventListener.proxySelectStart(call, url)proxies = selectProxies()nextProxyIndex = 0eventListener.proxySelectEnd(call, url, proxies)}

 val uri = url.toUri() 函数扒到底,实际获取hostName的执行代码如下。java.net.Uri包解uri时,如果uri的host不合法,则降级设置host为null。

java.net.uri类节选代码
  private int parseAuthority(int start, int n)throws URISyntaxException{...if (serverChars) {// Might be (probably is) a server-based authority, so attempt// to parse it as such.  If the attempt fails, try to treat it// as a registry-based authority.try {//此处解析hostName,不合法的话会扔出URISyntaxException异常q = parseServer(p, n);if (q < n)failExpecting("end of authority", q);authority = substring(p, n);} catch (URISyntaxException x) {// Undo results of failed parseuserInfo = null;//host被赋值为空指针host = null;port = -1;if (requireServerAuthority) {// If we're insisting upon a server-based authority,// then just re-throw the exceptionthrow x;} else {// ex = x;q = p;}}}...return n;}

参考:JDK(java.net.URL) 中的 一个 "bug" | 唐磊的个人博客

http://www.jinmujx.cn/news/78280.html

相关文章:

  • 手机网站建站教育模板考研培训机构排名
  • 天津网站设计方案网络推广公司怎么找客户
  • 网站开发 h5宁波seo关键词如何优化
  • 电商网站seo方案网络seo啥意思
  • 阿里云网站如何建设视频国家职业技能培训学校
  • 深圳网站建房网络项目免费的资源网
  • 云主机玩游戏快速排名优化
  • 成都那家做网站好今天的热搜榜
  • 济南 网站建设 域名注册职业培训机构排名
  • php做电影网站企业培训考试
  • 闵行区个人网页设计用户体验网站推广seo招聘
  • 网站开发的职责徐州seo推广优化
  • 无锡找做网站社群营销的案例
  • 武汉专业网站做网页b2b平台有哪些
  • 揭阳专业做网站公司网站一键收录
  • 自己做的网站服务器在哪里营销型网站的分类不包含
  • 房产信息网显示限售新人学会seo
  • 网络促销分类 网站促销网络服务包括
  • 建行网站注册用户名怎么填百度竞价推广关键词优化
  • WordPress客户端百度seo词条优化
  • 成都网站建设科技公成都百度搜索排名优化
  • 网站建设硬件和软件技术环境配置网站搭建公司哪家好
  • 网站开发系统架构图广州建网站的公司
  • wordpress优化数据库变大武汉seo推广优化
  • 织梦网站模板安装重庆电子商务seo
  • 公司展示厅设计seo搜索引擎优化就业指导
  • 循环视频做网站背景2345网址导航官方网站
  • 做网站什么费用百度搜索引擎提交入口
  • wordpress mysqlliwindows优化大师自动安装
  • 做网站寄生虫需要哪些东西友情链接平台站长资源