UnknownHostException: name or service not known

后端 未结 3 2293
时光说笑
时光说笑 2021-02-20 08:28

I\'m attempting to return some data from an API using OkHttpClient in com.squareup.okhttp. I\'ve run into a few errors that i have eventually been able to overcome but i can\'t

3条回答
  •  情歌与酒
    2021-02-20 08:58

    Expanding on zhenbo xu's great answer this is what I did to automate things with sed in EC2.

    sudo sed -i -e '/127.0.0.1/ s/\(localhost\)/'$(hostname)' \1/' /etc/hosts

    Note that to allow variable expansion the single quotes end and restart around the subshell call.

    hostname is an executable on some Linux systems (but maybe not all, so you can use an environment variable instead,or remove the quotes around the subshell and use static string).

    The \1 is sed magic, it puts the "captured" search string (s/search/replacement/) in the escaped parentheses back into the replacement string.

提交回复
热议问题