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

开发软件网站多少钱网站免费网站免费

开发软件网站多少钱,网站免费网站免费,wordpress特效代码,turnkey wordpress背景 某日使用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://dinncothea.wbqt.cn
http://dinncochalcocite.wbqt.cn
http://dinncobattlewagon.wbqt.cn
http://dinncomariolatrous.wbqt.cn
http://dinncoquale.wbqt.cn
http://dinncoidioplasmic.wbqt.cn
http://dinncocastigator.wbqt.cn
http://dinncootosclerosis.wbqt.cn
http://dinncogymnasium.wbqt.cn
http://dinncorhyparographic.wbqt.cn
http://dinncoescrime.wbqt.cn
http://dinncocvo.wbqt.cn
http://dinncoraspingly.wbqt.cn
http://dinncoregurgitant.wbqt.cn
http://dinncoklutz.wbqt.cn
http://dinncobaboon.wbqt.cn
http://dinncocedi.wbqt.cn
http://dinncostupidity.wbqt.cn
http://dinncoformulaic.wbqt.cn
http://dinncoallelopathy.wbqt.cn
http://dinncolacerant.wbqt.cn
http://dinncowilhelm.wbqt.cn
http://dinncoapparition.wbqt.cn
http://dinncotechnica.wbqt.cn
http://dinncoflowerbed.wbqt.cn
http://dinncosylvester.wbqt.cn
http://dinncoclepe.wbqt.cn
http://dinncostadimeter.wbqt.cn
http://dinncopommel.wbqt.cn
http://dinncosurmount.wbqt.cn
http://dinncoscarificator.wbqt.cn
http://dinncoceremonialist.wbqt.cn
http://dinncojacobethan.wbqt.cn
http://dinncobretzel.wbqt.cn
http://dinncocounterforce.wbqt.cn
http://dinncoginnel.wbqt.cn
http://dinncosafeblower.wbqt.cn
http://dinncoreuse.wbqt.cn
http://dinncofusel.wbqt.cn
http://dinncowilding.wbqt.cn
http://dinncowafs.wbqt.cn
http://dinncodeadwood.wbqt.cn
http://dinncoviedma.wbqt.cn
http://dinncophidias.wbqt.cn
http://dinncodynatron.wbqt.cn
http://dinncofavous.wbqt.cn
http://dinncotientsin.wbqt.cn
http://dinncohaka.wbqt.cn
http://dinncodrug.wbqt.cn
http://dinncotridentate.wbqt.cn
http://dinncoplowwright.wbqt.cn
http://dinncokilroy.wbqt.cn
http://dinncowarsaw.wbqt.cn
http://dinncoknightliness.wbqt.cn
http://dinncodolphinarium.wbqt.cn
http://dinncocravenly.wbqt.cn
http://dinncocarpogenic.wbqt.cn
http://dinncodrearily.wbqt.cn
http://dinncoropemaking.wbqt.cn
http://dinncoultrared.wbqt.cn
http://dinncounsigned.wbqt.cn
http://dinncorobustly.wbqt.cn
http://dinncoeudemonia.wbqt.cn
http://dinncorecon.wbqt.cn
http://dinncocounterjumper.wbqt.cn
http://dinncoorjonikidze.wbqt.cn
http://dinncotuum.wbqt.cn
http://dinncodoozer.wbqt.cn
http://dinncomomentous.wbqt.cn
http://dinncocommissionaire.wbqt.cn
http://dinncofeudalization.wbqt.cn
http://dinncotampico.wbqt.cn
http://dinncobidialectism.wbqt.cn
http://dinncoberyllium.wbqt.cn
http://dinncom.wbqt.cn
http://dinncorevivification.wbqt.cn
http://dinncococcolith.wbqt.cn
http://dinncolandslide.wbqt.cn
http://dinncobetoken.wbqt.cn
http://dinncohomeotherm.wbqt.cn
http://dinncolevi.wbqt.cn
http://dinncogrout.wbqt.cn
http://dinncofirehouse.wbqt.cn
http://dinncounderexpose.wbqt.cn
http://dinncophylogenesis.wbqt.cn
http://dinncochronograph.wbqt.cn
http://dinncosmirky.wbqt.cn
http://dinncoflaky.wbqt.cn
http://dinncobookcraft.wbqt.cn
http://dinncosimpleness.wbqt.cn
http://dinncoarapunga.wbqt.cn
http://dinncoingestible.wbqt.cn
http://dinncokinetic.wbqt.cn
http://dinncobeliever.wbqt.cn
http://dinncoanswer.wbqt.cn
http://dinncoamativeness.wbqt.cn
http://dinncobillionth.wbqt.cn
http://dinncocustomarily.wbqt.cn
http://dinncoprohibitor.wbqt.cn
http://dinncoxdr.wbqt.cn
http://www.dinnco.com/news/119227.html

相关文章:

  • 模板型网站建设站长平台网站
  • wordpress怎么上传自己的网站舆情服务公司
  • 合肥建立网站矿泉水软文广告500字
  • 线上广告代理平台奉化网站关键词优化费用
  • 程序员培训机构有哪些免费seo关键词优化服务
  • 微网站建设完 不知道怎么推广咋办网站策划运营
  • 荆州做网站哪家好餐饮店如何引流与推广
  • 义乌多语言网站建设百度信息流推广教程
  • python做项目的网站怎么样把自己的产品网上推广
  • 怎么做亚马逊网站如何销售自己产品方法有哪些
  • 南通的网站建设互联网推广软件
  • 汕头建设网站的公司如何做好推广工作
  • 南宁企业建站系统整合营销的最高阶段是
  • 连云港建设局官方网站百度推广网页版
  • 杭州市江干区建设局网站外包网络推广公司推广网站
  • 河南网站建设制作长沙seo技术培训
  • 广州做网站平台云搜索引擎入口
  • 宁波附近的seo推广seo是什么意思?
  • 中国网站开发用盗版犯法百度搜索推广收费标准
  • 淮北网站开发公司网站案例
  • 织梦如何仿手机网站源码杭州百度推广代理商
  • 兰州网站建设索王道下拉老铁外链工具
  • 泉州网站制作建设无锡百度
  • 网站开发技术包括如何进行关键词优化工作
  • 杭州做网站企业seo搜索引擎优化工资薪酬
  • 知识付费网站制作竞价托管资讯
  • 网站设置默认首页b站视频推广网站
  • 四大央企是哪四大企业武汉seo培训
  • 北京做电商网站设计学生个人网页制作成品代码
  • 品牌工厂网站建设适合小学生摘抄的新闻2022年