精华内容
下载资源
问答
  • baseURL

    千次阅读 2021-06-21 11:12:34
    # baseURL # 需求分析 有些时候,我们会请求某个域名下的多个接口,我们不希望每次发送请求都填写完整的 url,希望可以配置一个 baseURL,之后都可以传相对路径。如下: const instance = axios.create({ baseURL: ...

    有些时候,我们会请求某个域名下的多个接口,我们不希望每次发送请求都填写完整的 url,希望可以配置一个 baseURL,之后都可以传相对路径。如下:

    const instance = axios.create({
      baseURL: 'https://some-domain.com/api'
    })
    
    instance.get('/get')
    
    instance.post('/post')
    

    我们一旦配置了 baseURL,之后请求传入的 url 都会和我们的 baseURL 拼接成完整的绝对地址,除非请求传入的 url 已经是绝对地址。

    首先修改一下类型定义。

    types/index.ts

    export interface AxiosRequestConfig {
      // ...
      baseURL?: string
    }
    

    接下来实现 2 个辅助函数。

    helpers/url.ts

    export function isAbsoluteURL(url: string): boolean {
      return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url)
    }
    
    export function combineURL(baseURL: string, relativeURL?: string): string {
      return relativeURL ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL
    }
    

    最后我们来调用这俩个辅助函数。

    core/dispatchRequest.ts

    function transformURL(config: AxiosRequestConfig): string {
      let { url, params, paramsSerializer, baseURL } = config
      if (baseURL && !isAbsoluteURL(url!)) {
        url = combineURL(baseURL, url)
      }
      return buildURL(url!, params, paramsSerializer)
    }
    

    const instance = axios.create({
      baseURL: 'https://img.mukewang.com/'
    })
    
    instance.get('5cc01a7b0001a33718720632.jpg')
    
    instance.get('https://img.mukewang.com/szimg/5becd5ad0001b89306000338-360-202.jpg')
    

    这个 demo 非常简单,我们请求了慕课网的 2 张图片,注意当第二个请求 url 已经是绝对地址的时候,我们并不会再去拼接 baseURL

    至此,ts-axios 就实现了 baseURL 的配置功能,接下来我们来实现 ts-axios 的静态方法扩展。

    展开全文
  • 背景 ... 前端大鸟:简单,我们是采用retrofit+okhttp的网络框架,基础url是配置的,改下就可以,敲代码… //原有Retrofit配置 new Retrofit ....baseUrl("https://xxx.xxx.x.x") .client(getOkHttpC

    背景

    后台大佬:我们api目前不够安全,不能直接通过原有地址(https://xxx.xxx.x.x/#/#)访问了,要通过网关访问,所有域名后面加多个路径(https://xxx.xxx.x.x/1/#/#);
    前端大鸟:简单,我们是采用retrofit+okhttp的网络框架,基础url是配置的,改下就可以,敲代码…

    //原有Retrofit配置
       new Retrofit
    .Builder()
    .baseUrl("https://xxx.xxx.x.x")  
    .client(getOkHttpClient())
    
    //修改后Retrofit配置
       new Retrofit
    .Builder()
    .baseUrl("https://xxx.xxx.x.x/1/")  //带path最后必须加/否则报错
    .client(getOkHttpClient())
    
    //其中api声明
    @POST("/#/#")
    Observable A();
    

    但是运行起来后会发现baseurl新增的**/1/没生效的**,实际访问地址还是https://xxx.xxx.x.x/#/#,并不是我们期望的https://xxx.xxx.x.x/1/#/#
    是不是第一反应是编译器的问题,反正我是这样以为,甚至关机重启后问题依旧,其实这里面是由于retrofit导致的,

    解决方案就是删除api声明最前面的/

    //修改后的api声明 少了最开始的/
    @POST("#/#")
    Observable A();
    

    以下是我的问题分析,
    首先是看下baseUrl设置有没异常,这时候看下Retrifit的baseUrl()方法

    /**
     * Set the API base URL.
     */
    public Builder baseUrl(String baseUrl) {
      return baseUrl(HttpUrl.get(baseUrl));
    }
    
    //我们传进来的base url字符串最后以HttpUrl变量保存在retrofit实例中
    public Builder baseUrl(HttpUrl baseUrl) {
      this.baseUrl = baseUrl;
      return this;
    }
    

    这里面有个不懂的问题-项目代码是用java写的,照理说HttpUrl.get(String)方法应该也是java类型的,但是HttpUrl中并没有get(String)类型,断点后发现是直接调用kotlin的HttpUrl.get(String)方法,那该类就按kotlin分析

    其中HttpUrl.get(String)方法构建一个HttpUrl对象

    @JvmStatic
    @JvmName("get") fun String.toHttpUrl(): HttpUrl = Builder().parse(null, this).build()
    

    我们先先看parse(null, this)方法,其中null是base,this是传进来的baseUrl,也就是 https://xxx.xxx.x.x/1/#/#
    省略代码如下

    internal fun parse(base: HttpUrl?, input: String): Builder {
     val slashCount = input.slashCount(pos, limit)//0
      if (slashCount >= 2 || base == null || base.scheme != this.scheme) {//1
            //...
              if (portColonOffset + 1 < componentDelimiterOffset) {//2
                host = input.percentDecode(pos = pos, limit = portColonOffset).toCanonicalHost()
                port = parsePort(input, portColonOffset + 1, componentDelimiterOffset)
              } else {
                host = input.percentDecode(pos = pos, limit = portColonOffset).toCanonicalHost()
                port = defaultPort(scheme!!)
              }
            //...
            
      } else {
        this.host = base.host
        this.port = base.port
        this.encodedPathSegments.clear()
        this.encodedPathSegments.addAll(base.encodedPathSegments)
      }      
      val pathDelimiterOffset = input.delimiterOffset("?#", pos, limit)
      resolvePath(input, pos, pathDelimiterOffset)//3
      ..... 
    

    首先baseUrl进来,slashCount()方法是计算url中"\\和"/"的个数(也就是base url是否包含//或者\),并且传进来的base也为null,故标记1处的if判断会为true ,进入标记2处设置域名和端口,然后我们接着往下看,resolvePath方法

    private fun resolvePath(input: String, startPos: Int, limit: Int) {
      val c = input[pos]
      if (c == '/' || c == '\\') {
        // Absolute path: reset to the default "/".
        encodedPathSegments.clear()
        encodedPathSegments.add("")
        pos++
      } else {
        encodedPathSegments[encodedPathSegments.size - 1] = ""
      }
      var i = pos
      while (i < limit) {//1
        val pathSegmentDelimiterOffset = input.delimiterOffset("/\\", i, limit)
        val segmentHasTrailingSlash = pathSegmentDelimiterOffset < limit
        push(input, i, pathSegmentDelimiterOffset, segmentHasTrailingSlash, true)//1
        i = pathSegmentDelimiterOffset
        if (segmentHasTrailingSlash) i++
      }
    }
    

    其中在1处会while循环找出我们的path位置,然后调用push方法 如下:

    /** Adds a path segment. If the input is ".." or equivalent, this pops a path segment. */
    private fun push(pos:String,...省略) {
      val segment = input.canonicalize(
          pos = pos,
          limit = limit,
          encodeSet = PATH_SEGMENT_ENCODE_SET,
          alreadyEncoded = alreadyEncoded
      )
      if (encodedPathSegments[encodedPathSegments.size - 1].isEmpty()) {
        encodedPathSegments[encodedPathSegments.size - 1] = segment
      } else {
        encodedPathSegments.add(segment)
      }
      if (addTrailingSlash) {
        encodedPathSegments.add("")
      }
    }
    

    input.canonicalize方法会根据传进来的pos找出path名称,插入encodedPathSegments集合中,也就是我们新增的path(/1)在此处被保存

    其中encodedPathSegments字段要关注了(敲黑板),就是我们要分析的东西

      /**
       * A list of encoded path segments like `["a", "b", "c"]` for the URL `http://host/a/b/c`. This
       * list is never empty though it may contain a single empty string.
       *
       * | URL                     | `encodedPathSegments()` |
       * | :---------------------- | :---------------------- |
       * | `http://host/`          | `[""]`                  |
       * | `http://host/a/b/c`     | `["a", "b", "c"]`       |
       * | `http://host/a/b%20c/d` | `["a", "b%20c", "d"]`   |
       */
      @get:JvmName("encodedPathSegments") val encodedPathSegments: List
    

    注释已经蛮明显了,就是存储我们传进来的url中包含的path集合,到此parse部分就完成了。

    @JvmStatic
    @JvmName("get") fun String.toHttpUrl(): HttpUrl = Builder().parse(null, this).build()
    

    接下来就是build()方法

    fun build(): HttpUrl {
      @Suppress("UNCHECKED_CAST") // percentDecode returns either List or List.
      return HttpUrl(
          scheme = scheme ?: throw IllegalStateException("scheme == null"),
          username = encodedUsername.percentDecode(),
          password = encodedPassword.percentDecode(),
          host = host ?: throw IllegalStateException("host == null"),
          port = effectivePort(),
          pathSegments = encodedPathSegments.map { it.percentDecode() },
          queryNamesAndValues = encodedQueryNamesAndValues?.map { it?.percentDecode(plusIsSpace = true) },
          fragment = encodedFragment?.percentDecode(),
          url = toString()
      )
    }
    

    都是之前配置的一些参数,没提到的也不要紧毕竟我们关注的是path为什么不生效,这里可以看到url是通过toString函数生成,我们跟进去看下

    override fun toString(): String {
      return buildString {
        append(scheme)
        append("://")
        append(host)
        encodedPathSegments.toPathString(this)//添加path
     }
    }
    

    encodedPathSegments.toPathString(this)方法如下,就是拼装进去

    internal fun List.toPathString(out: StringBuilder) {
      for (i in 0 until size) {
        out.append('/')
        out.append(this[i])
      }
    }
    

    至此baseurl已经设置上去,这时候url还是https://xxx.xxx.x.x/1/ 这时候还没问题的,

    那问题到底在哪里呢?

    我们看下请求接口时 Request对象的构建,因为最终的url是在此处赋值。
    由于源码一步步看太长了,我们直接从关键类代码看
    RequestFactory类-OkHttpCall构建Request时会调用该类的create方法,

      okhttp3.Request create(Object[] args) throws IOException {
       //...
        RequestBuilder requestBuilder =
            new RequestBuilder(
                httpMethod,
                baseUrl,
                relativeUrl,
                headers,
                contentType,
                hasBody,
                isFormEncoded,
                isMultipart);
        return requestBuilder.get().tag(Invocation.class, new Invocation(method, argumentList)).build();
      }
    

    我们看下requestBuilder.get()方法,简洁代码…

    Request.Builder get() {
        HttpUrl url;
        url = baseUrl.resolve(relativeUrl);
        return requestBuilder.url(url).headers(headersBuilder.build()).method(method, body);
    }
    

    可以看出baseUrl是之前设置的对象,relativeUrl是我们在api声明的路径(https://xxx.xxx.x.x/1/#/#中的**/#/#**)继续跟进resolve方法

      public @Nullable HttpUrl resolve(String link) {
        Builder builder = newBuilder(link);
        return builder != null ? builder.build() : null;
      }
    

    还是构造模式,继续根据newBuilder,提醒下newBuilder是HttpUrl内部方法

    Builder builder = new Builder();
    Builder.ParseResult result = builder.parse(this, link);
    return result == Builder.ParseResult.SUCCESS ? builder : null;
    

    what?? 又是parse方法,不是又跟前面的分析一样了吗? 其实这时候还是不一样,这时候parse的第一个参数是this,也就是我们一开始创建的HttpUrl对象,我们这时候挑不同的说,就

    internal fun parse(base: HttpUrl?, input: String): Builder {
     val slashCount = input.slashCount(pos, limit)
      if (slashCount >= 2 || base == null || base.scheme != this.scheme) {//1
            //...
              if (portColonOffset + 1 < componentDelimiterOffset) {
                host = input.percentDecode(pos = pos, limit = portColonOffset).toCanonicalHost()
                port = parsePort(input, portColonOffset + 1, componentDelimiterOffset)
              } else {
                host = input.percentDecode(pos = pos, limit = portColonOffset).toCanonicalHost()
                port = defaultPort(scheme!!)
              }
            //...
            
      } else {//2
        this.host = base.host
        this.port = base.port
        this.encodedPathSegments.clear()
        this.encodedPathSegments.addAll(base.encodedPathSegments)
      }      
      val pathDelimiterOffset = input.delimiterOffset("?#", pos, limit)
      resolvePath(input, pos, pathDelimiterOffset)//3
      ..... 
    

    这时会走标记2处,因为path不包含"\"和含有base(HttpUrl)
    然后会把baseurl的path加进当前的encodedPathSegments,既然把baseurl的path加进来了,为什么最终的的ur不包含呢?笔者也是在这里卡了好久。
    我们接着看标记3

    private fun resolvePath(input: String, startPos: Int, limit: Int) {
      val c = input[pos]
      if (c == '/' || c == '\\') {
        // Absolute path: reset to the default "/".
        encodedPathSegments.clear()//1
        encodedPathSegments.add("")
        pos++
      } else {
        encodedPathSegments[encodedPathSegments.size - 1] = ""
      }
      var i = pos
      while (i < limit) {
        val pathSegmentDelimiterOffset = input.delimiterOffset("/\\", i, limit)
        val segmentHasTrailingSlash = pathSegmentDelimiterOffset < limit
        push(input, i, pathSegmentDelimiterOffset, segmentHasTrailingSlash, true)//1
        i = pathSegmentDelimiterOffset
        if (segmentHasTrailingSlash) i++
      }
    }
    

    看到这里就清楚了,这时候inputs是/#/#,startPos是0,也就是说

    path里面是/开头 则把baseurl的encodedPathSegments(path集合)给clear了,所以我们设置的会没有效果。

    //其中api声明
    @POST("/#/#")
    Observable A();
    

    下面的就是添加声明的path到encodedPathSegments,最后toString生成请求的api,详细的话就看源码了

    记录一下一次修改baseUrl不生效的坑,打完收工。

    展开全文
  • Retrofit动态修改BaseUrl

    2021-06-07 13:31:34
    // 初始化Retrofit retrofit = new Retrofit.Builder() .client(client) .baseUrl(ConstantUrl.BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory...

    1.给Retrofit添加BaseUrlManagerInterceptor拦截器。

    private static final String          TAG = "RetrofitManager";
    private static       RetrofitManager manager;
    private              Retrofit        retrofit;
    
    /**
     * 私有构造器 无法外部创建
     * 初始化必要对象和参数
     */
    private RetrofitManager() {
       // 初始化okhttp
       OkHttpClient client = new OkHttpClient.Builder()
                           .connectTimeout(5 * 1000, TimeUnit.MILLISECONDS)
                           .readTimeout(5 * 1000, TimeUnit.MILLISECONDS)
                           .writeTimeout(5 * 1000, TimeUnit.MILLISECONDS)
                           .addInterceptor(new BaseUrlManagerInterceptor(BaseApplication.getInstance()))
                           .proxy(Proxy.NO_PROXY)
                           .build();
       
       // 初始化Retrofit
       retrofit = new Retrofit.Builder()
                   .client(client)
                   .baseUrl(ConstantUrl.BASE_URL)
                   .addConverterFactory(GsonConverterFactory.create())
                   .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                   .build();
    }
    
    public static RetrofitManager getInstance() {
       if (manager == null) {
          synchronized (RetrofitManager.class) {
             if (manager == null) {
                manager = new RetrofitManager();
             }
          }
       }
       return manager;
    }
    
    public Retrofit getRetrofit() {
       return retrofit;
    }
    
    

    //创建一个拦截器

    public class BaseUrlManagerInterceptor implements Interceptor {
       
       private static final String          TAG = "BaseUrlManagerInterceptor";
       private              BaseApplication baseApplication;
       
       public BaseUrlManagerInterceptor(BaseApplication baseApplication) {
          super();
          this.baseApplication = baseApplication;
       }
       
       @Override
       public Response intercept(Chain chain) throws IOException {
          //获取原始的originalRequest
          Request originalRequest = chain.request();
          //获取originalRequest的创建者builder
          Request.Builder builder = originalRequest.newBuilder();
          //获取当前的url
          HttpUrl oldUrl = originalRequest.url();
          LogManager.i(TAG, "intercept:------------oldUrl---------->" + oldUrl);
          
          //获取头信息的集合如:jeapp ,njeapp ,mall
          List<String> urlnameList = originalRequest.headers("urlname");
          if (urlnameList != null && urlnameList.size() > 0) {
             //删除原有配置中的值,就是namesAndValues集合里的值
             builder.removeHeader("urlname");
             //获取头信息中配置的value,如:manage或者mdffx
             String urlname = urlnameList.get(0);
             LogManager.i(TAG, "intercept:-------urlname------" + urlname);
             HttpUrl baseURL = null;
             //根据头信息中配置的value,来匹配新的base_url地址
             if (!TextUtils.isEmpty(urlname)) {
                switch (urlname) {
                   case ConstantData.TO_FIRST_PAGR_FLAG:
                      baseURL = HttpUrl.parse(ConstantData.TO_FIRST_PAGR_URL);
                      break;
                   case ConstantData.TO_PROJECT_FLAG:
                      baseURL = HttpUrl.parse(ConstantData.TO_PROJECT_URL);
                      break;
                   //                    case ConstantData.TO_PROJECT_FLAG:
                   //                        baseURL = HttpUrl.parse(ConstantData.TO_PROJECT_URL);
                   //                        break;
                   case ConstantData.TO_RESOURCE_FLAG:
                      baseURL = HttpUrl.parse(ConstantData.TO_RESOURCE_URL);
                      break;
                   case ConstantData.TO_MINE_FLAG:
                      baseURL = HttpUrl.parse(ConstantData.TO_MINE_URL);
                      break;
                   case ConstantData.TO_USER_DATA_FLAG:
                      baseURL = HttpUrl.parse(ConstantData.TO_USER_DATA_URL);
                      break;
                   default:
                      break;
                }
                //          if ("jeapp".equals(urlname)) {
                //             baseURL = HttpUrl.parse(ConstantData.PRE_URL);
                //          } else if ("njeapp".equals(urlname)) {
                //             baseURL = HttpUrl.parse(ConstantData.PRE_NEW_URL);
                //          } else if ("mall".equals(urlname)) {
                //             baseURL = HttpUrl.parse(ConstantData.MALL_URL);
                //          }
                
                LogManager.i(TAG, "intercept:-----oldUrl-----" + oldUrl.toString());
                //重建新的HttpUrl,需要重新设置的url部分
                HttpUrl newHttpUrl = oldUrl.newBuilder()
                                   .scheme(baseURL.scheme())//http协议如:http或者https
                                   .host(baseURL.host())//主机地址
                                   .port(baseURL.port())//端口
                                   .build();
                LogManager.i(TAG, "intercept:------scheme----" + baseURL.scheme());
                LogManager.i(TAG, "intercept:-----host-----" + baseURL.host());
                LogManager.i(TAG, "intercept:-----port-----" + baseURL.port());
                LogManager.i(TAG, "intercept:-----newHttpUrl-----" + newHttpUrl.toString());
                
                //获取处理后的新newRequest
                Request.Builder newBuilder = builder.url(newHttpUrl);
                
                Request newRequest = newBuilder.build();
                return chain.proceed(newRequest);
             }
             originalRequest = builder.build();
             return chain.proceed(originalRequest);
          } else {
             originalRequest = builder.build();
             return chain.proceed(originalRequest);
          }
          
       }
    }

     

    2.添加请求的头部信息

    @Headers("urlname:" + ConstantData.TO_FIRST_PAGR_FLAG)
    @GET(ConstantUrl.FIRST_PAGE_DETAILS_URL)
    Observable<ResponseBody> getFirstPageDetails(@QueryMap Map<String, String> bodyParams);
    

    //常量类

    public class ConstantData {
       
       public static final String TO_FIRST_PAGR_FLAG = "FIRST_PAGR_FLAG";
       public static final String TO_PROJECT_FLAG    = "PROJECT_FLAG";
       public static final String TO_RESOURCE_FLAG   = "RESOURCE_FLAG";
       public static final String TO_MINE_FLAG       = "MINE_FLAG";
       public static final String TO_USER_DATA_FLAG  = "USER_DATA_FLAG";
       
       public static final String TO_FIRST_PAGR_URL = ConstantUrl.BASE_URL;
       public static final String TO_PROJECT_URL    = ConstantUrl.BASE_URL3;
       public static final String TO_RESOURCE_URL   = ConstantUrl.BASE_URL2;
       public static final String TO_MINE_URL       = ConstantUrl.BASE_URL;
       public static final String TO_USER_DATA_URL  = ConstantUrl.BASE_URL0;
       
    }

     

    public class ConstantUrl {
       
       //正式地址(此地址无效,请替换)
       public static final String BASE_URL0 = "https://is.snssdk.net/";
       
       public static final String BASE_URL  = "http://is.snssdk.com/";
       public static final String BASE_URL2 = "http://gank.io/";
       public static final String BASE_URL3 = "https://wanandroid.com/";
    }
    

     

    添加此拦截器就可以在app在调用不同模块时,发起不同url的请求。如需要完整项目,请联系qq1164688204。

    项目功能介绍:RxJava2和Retrofit2项目,添加自动管理token功能,添加RxJava2生命周期管理,使用App架构设计是MVP模式和MVVM模式,同时使用组件化,部分代码使用Kotlin,此项目持续维护中。

    展开全文
  • mirrorlist 是由 yum 程序 自行去捉映射站台, baseurl 则是指定固定的一个软件库网址!我们刚刚找到的网址放到 这里来啦! enable=1:就是让这个软件库被启动。如果不想启动可以使用 enable=0 喔! gpgcheck=1:还...

    一、在使用CentOS 6.5的图形化界面时,突然蹦出这个界面:

    在这里插入图片描述
    这个问题一开始我遗留了很久没有解决,查了很多方式,包括把/etc/yum.repos.d/CentOS-Base.repo 改成备份等等方式。最终我在看书的时候,发现了这个问题的解决方案。

    二、CentOS-Base.repo配置文件学习

    1.这个是yum源的配置文件,其中以base为例:
    	[base]:代表软件库的名字!中括号一定要存在,里面的名称则可以随意取。但是不能有 两个相同的软件库名称, 否则 yum 会不晓得该到哪里去找软件库相关软件清单文件。
        name:只是说明一下这个软件库的意义而已,重要性不高! mirrorlist=:列出这个软件库可以使用的映射站台,如果不想使用,可以注解到这行;
        baseurl=:这个最重要,因为后面接的就是软件库的实际网址! mirrorlist 是由 yum 程序 自行去捉映射站台, baseurl 则是指定固定的一个软件库网址!我们刚刚找到的网址放到 这里来啦! enable=1:就是让这个软件库被启动。如果不想启动可以使用 enable=0 喔! 
        gpgcheck=1:还记得 RPM 的数码签章吗?这就是指定是否需要查阅 RPM 文件内的数 码签章! 
    	gpgkey=:就是数码签章的公钥档所在位置!使用默认值即可
    

    三、问题解决:针对各个CentOS版本修改CentOS-Base.repo文件

    注意在修改前做好该配置文件的备份!!!
    注意修改完成后运行yum makecache生成元数据缓存!!!
    

    CentOS 6:
    /etc/yum.repos.d/CentOS-Base.repo

    # CentOS-Base.repo
    #
    	#The mirror system uses the connecting IP address of the client and the
    #update status of each mirror to pick mirrors that are updated to and
    #geographically close to the client.  You should use this for CentOS updates
    #unless you are manually picking other mirrors.
    #If the mirrorlist= does not work for you, as a fall back you can try the
    #remarked out baseurl= line instead.
    #
    #
     
    [base]
    name=CentOS-$releasever - Base - mirrors.ustc.edu.cn
    baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
    gpgcheck=1
    gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
     
    #released updates
    [updates]
    name=CentOS-$releasever - Updates - mirrors.ustc.edu.cn
    baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
    gpgcheck=1
    gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
     
    #additional packages that may be useful
    [extras]
    name=CentOS-$releasever - Extras - mirrors.ustc.edu.cn
    baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
    gpgcheck=1
    gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
     
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-$releasever - Plus - mirrors.ustc.edu.cn
    baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
    gpgcheck=1
    enabled=0
    gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
     
    #contrib - packages by Centos Users
    [contrib]
    name=CentOS-$releasever - Contrib - mirrors.ustc.edu.cn
    baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/contrib/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
    gpgcheck=1
    enabled=0
    gpgkey=http://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-6
    

    CentOS 7:
    /etc/yum.repos.d/CentOS-Base.repo 文件:

    # CentOS-Base.repo
    #The mirror system uses the connecting IP address of the client and the
    #update status of each mirror to pick mirrors that are updated to and
    #geographically close to the client.  You should use this for CentOS updates
    #unless you are manually picking other mirrors.
    #If the mirrorlist= does not work for you, as a fall back you can try the
    #remarked out baseurl= line instead.
    
    [base]
    name=CentOS-$releasever - Base
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    #released updates
    [updates]
    name=CentOS-$releasever - Updates
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    #additional packages that may be useful
    [extras]
    name=CentOS-$releasever - Extras
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-$releasever - Plus
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7	
    

    CentOS 8:

    /etc/yum.repos.d/CentOS-Linux-BaseOS.repo 文件:

    #CentOS-Linux-BaseOS.repo
    #
    #The mirrorlist system uses the connecting IP address of the client and the
    #update status of each mirror to pick current mirrors that are geographically
    #close to the client.  You should use this for CentOS updates unless you are
    #manually picking other mirrors.
    #
    #If the mirrorlist does not work for you, you can try the commented out
    #baseurl line instead.
    
    [baseos]
    name=CentOS Linux $releasever - BaseOS
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/BaseOS/$basearch/os/
    gpgcheck=1
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    

    /etc/yum.repos.d/CentOS-Linux-Extras.repo 文件:

    #CentOS-Linux-Extras.repo
    #
    #The mirrorlist system uses the connecting IP address of the client and the
    #update status of each mirror to pick current mirrors that are geographically
    #close to the client.  You should use this for CentOS updates unless you are
    #manually picking other mirrors.
    #
    #If the mirrorlist does not work for you, you can try the commented out
    #baseurl line instead.
    
    [extras]
    name=CentOS Linux $releasever - Extras
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/os/
    gpgcheck=1
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    

    /etc/yum.repos.d/CentOS-Linux-AppStream.repo 文件:

    #CentOS-Linux-AppStream.repo
    #
    #The mirrorlist system uses the connecting IP address of the client and the
    #update status of each mirror to pick current mirrors that are geographically
    #close to the client.  You should use this for CentOS updates unless you are
    #manually picking other mirrors.
    #
    #If the mirrorlist does not work for you, you can try the commented out
    #baseurl line instead.
    
    [appstream]
    name=CentOS Linux $releasever - AppStream
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/AppStream/$basearch/os/
    gpgcheck=1
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    

    /etc/yum.repos.d/CentOS-Linux-PowerTools.repo 文件:

    #CentOS-Linux-PowerTools.repo
    #
    #The mirrorlist system uses the connecting IP address of the client and the
    #update status of each mirror to pick current mirrors that are geographically
    #close to the client.  You should use this for CentOS updates unless you are
    #manually picking other mirrors.
    #
    #If the mirrorlist does not work for you, you can try the commented out
    #baseurl line instead.
    
    [powertools]
    name=CentOS Linux $releasever - PowerTools
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=PowerTools&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/PowerTools/$basearch/os/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    

    /etc/yum.repos.d/CentOS-Linux-Plus.repo 文件:

    #CentOS-Linux-Plus.repo
    #
    #The mirrorlist system uses the connecting IP address of the client and the
    #update status of each mirror to pick current mirrors that are geographically
    #close to the client.  You should use this for CentOS updates unless you are
    #manually picking other mirrors.
    #
    #If the mirrorlist does not work for you, you can try the commented out
    #baseurl line instead.
    
    [plus]
    name=CentOS Linux $releasever - Plus
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/os/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    

    (修改完成后运行 yum makecache)

    Tips:
    CentOS 源使用帮助:https://mirrors.ustc.edu.cn/help/centos.html
    
    展开全文
  • } public Retrofit getRetrofit(String baseUrl, NetConfigProvider configProvider, boolean useRx) { if (baseUrl == null || baseUrl.length() == 0) { throw new IllegalStateException("base url can not be ...
  • } 下面是对retrofit设置的URL解析及添加到拦截器中 /** * 对 {@link Request} 进行一些必要的加工, 执行切换 BaseUrl 的相关逻辑 * * @param request {@link Request} * @return {@link Request} */ public Request...
  • PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'" Error: Cannot find a valid baseurl for repo: base 解决方法如下(修改dns配置) vi /etc/resolv.conf 在此文件最后加入:nameserver 114.114....
  • Retrofit动态切换baseUrl

    2020-12-30 17:12:22
    使用retrofit动态切换baseUrl 通过okhttp自定义拦截器切换baseUrl 一开始怎么都不行,一直拿到都是旧 Url 怎么试都不行 没有改之前 //线上 public static final String BASE_SERVER_URL=...
  • 今天在搭建MySQL MHA 安装MHA node所需的perl...问题现象执行的命令yum install perl-DBD-MySQL -y报错信息如下:可以看出错误的关键字为 :Cannot find a valid baseurl for repo: base/7/x86_64。这个问题 说明...
  • axios封装 baseurl headers

    2021-06-09 21:16:12
    // 指定baseurl 都会跟这个地址 let axios_obj = axios.create({ baseUrl:'http://localhost/api/v1/' }) // 请求拦截器 axios_obj.interceptors.request.use(function(conf){ // console.log(conf) if(conf.url !...
  • axios如何设置baseUrl

    2021-08-06 14:58:48
    1、在请求api时,有时要去访问其他服务端的数据,之前我在本地... axios.defaults.baseURL='xxx.xxx.xxx'; Vue.prototype.$axios = axios; new Vue({ render: h => h(App), }).$mount('#app') xxx是你的api前缀路径。
  • 最近需要用一下centos6版本,发现使用yum时报cannot found a valid baseurl for repo:base 先说原因: 2020年12月2日官方结束了对CentOS 6.x的支持,导致使用yum安装或更新程序的时候出现错误 解决方案: 清空...
  • 本地配置 baseurl=file:// + 绝对路径 ftp配置 baseurl=ftp:// + 主机名或IP + 相对路径 http配置 baseurl=http:// + 主机名或IP + 相对路径 local.repo【本地】 [centos] name=centos baseurl=file:///opt/centos/...
  • Vue cli3 baseurl设置

    千次阅读 2020-12-23 08:00:01
    // 环境的切换if (process.env.NODE_ENV == 'development') {axios.defaults.baseURL = 'https://www.baidu.com';}else if (process.env.NODE_ENV == 'debug') {axios.defaults.baseURL = 'https://www.ceshi.com';}...
  • 注:注解@DefaultDomain只能使用一处,多处使用将编译不通过 多个baseUrl 在上面代码中,我们只需要传入一条完整的url链接,其实就已经实现了多个baseUrl的问题,然后,大部分开发者都喜欢将baseUrl 单独写在一个...
  • axios配置多个baseURL和请求拦截

    千次阅读 2021-02-04 10:23:57
    axios配置多个baseURL和请求拦截axios配置多个baseURL请求拦截 首先感谢godferyZhu大佬的文章 Vue 2.0 项目中Axios配置不同的baseURL,请求不同的域名接口的支持,基于这篇文章,我继续封装部分内容,若有不对的地方...
  • vue-cli3.0配置baseUrl

    千次阅读 2020-12-23 07:59:17
    我试过, config.baseUrl = '*',会报错。 还有是,我在生产环境配置时, baseUrl: '../', // 将构建好的文件输出到哪里 outputDir: 'dist/resources', indexPath:'./templates/login.html', // 放置静态资源的地方 ...
  • axios配置多个baseurl

    2021-07-14 13:46:53
    var repeatUrl = ""//防止重复提交 const http = axios.create({ timeout: 10000 * 12, baseURL: process.env.API_ROOT, //地址1 headers: { 'X-Requested-With': 'XMLHttpRequest' } }) const ...
  • 这时我们需要动态调用BaseURL来切换数据库。假设:有 database1, database2.api文件夹的架构如下:repositories│ Repository.js│ RepositoryFactory.js│ RepositoryInstance.js│ userRepository.js...
  • I am using a standard Vue starer webpack template with VueAxios installed. I want to configure axios using .env variable when building with dev...== 'undefined') { Vue.axios.defaults.baseURL = baseURL; }
  • vue添加axios,并且指定baseurl的方法

    千次阅读 2021-01-13 16:46:36
    本文主要介绍如何在vue项目中引入axios,并且在使用的时候指定baseurl。好,下面上货。1、首先需要的是一个vue项目,这个可以参考以前的文章。2、然后是npm install axios --save-dev3、在main.js中添加如下内容:...
  • axios.create({ baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url // withCredentials: true, // send cookies when cross-domain requests timeout: 5000 // request timeout }) // ...
  • 下面我将介绍三种环境的baseUrl配置开发环境、测试环境以及生产环境在vue-cli3中,npm run serve时会把process.env.NODE_ENV设置为‘development’;npm run build时会把process.env.NODE_ENV设置为‘production’;...
  • RetrofitUrlManagerLet Retrofit support multiple baseUrl and can be change the baseUrl at runtime.OverviewIntroduction以最简洁的 Api 让 Retrofit 同时支持多个 BaseUrl 以及动态改变 BaseUrl....
  • npm run build 后出现 baseUrl is not allowed. 问题描述: 执行npm run build 出错关键代码如下 vue.config.js: @Override module.exports={ baseUrl:'./' } 原因分析: vue-cli 3.3版本后baseUrl被...
  • 这几天写一个上传Excel表功能。 使用iview中的Upload...Upload :action="this.$baseUrl + 'customer_service_call_notification/add_customer_service_call_excel'" accept=".xlsx" :format="['xlsx']" :on-succe
  • axios封装多个baseUrl

    2021-02-24 14:57:12
    const createService = baseURL => { // 创建axios实例 const service = axios.create({ baseURL, // api的base_url timeout: 50000 // 请求超时时间 }); // request拦截器 service.interceptors....
  • 一般我们在开发vue项目的时候,有两种运行模式,一种是npm run serve,这种是本地开发, 此时process.env.NODE_ENV为'development';...因此我们在配置axios的baseUrl时,一般会这样判断://环境的切换axios.defa...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 151,491
精华内容 60,596
关键字:

baseurl

友情链接: r语言入门.zip