java.net.UnknownServiceException: CLEARTEXT communication to wanandroid.com not permitted by network

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/pengyu1801/article/details/87879850

java.net.UnknownServiceException: CLEARTEXT communication to wanandroid.com not permitted by network 

这个错误是在安卓P系统上当调用远程接口进行网络通信时报的错误。

这是因为新的保护机制对于仅使用安全通信的应用,Android 6.0 Marshmallow(API 级别 23)引入了两种机制来解决回退到明文通信的问题:(1) 在生产/安装库中,禁止明文通信,以及 (2) 在开发/QA 期间,在遇到任何非 TLS/SSL 通信时,予以记录或者触发崩溃。下文将更详细地介绍这两种机制。

2,解决方法:

如果一定要使用明文通信的话,则可以打开AndroidManifest.xml 文件,在 application 元素中添加:
 

android:usesCleartextTraffic="true"

备注:

1)为了安全,不建议上面的使用明文的通信方式,不过上面的这种方法可以作为一种临时的通信策略

2)如果声明不使用明文通信,则可以在application元素中添加:

android:usesCleartextTraffic=”false” 
此声明指示该应用不使用明文网络通信,并使 Android Marshmallow 的平台网络堆栈禁止该应用中的明文通信。例如,如果您的应用意外尝试通过 HTTP 明文请求登录用户,该请求将被阻止,该用户的身份和密码信息不会泄露到网络上。

展开阅读全文

thread_setschedparam: Operation not permitted

06-26

/*rn *attr.c rn */rnrn#include rn#include rn#include rn#include rn#include rnrn#define handle_error_en(en, msg) \rn do errno = en; perror(msg); exit(EXIT_FAILURE); while (0)rn rnstatic void display_sched_attr(int policy, struct sched_param *param)rn rn switch(policy) rn rn case SCHED_FIFO:rn printf("policy=%s,priority=%d\n","SCHED_FIFO",param->sched_priority);rn break;rn case SCHED_RR:rn printf("policy=%s,priority=%d\n","SCHED_RR",param->sched_priority);rn break;rn case SCHED_OTHER:rn printf("policy=%s,priority=%d\n","SCHED_OTHER",param->sched_priority);rn break; rn default:rn printf("Error:unknown optional.\n");rn break;rn rnrnstatic void display_inheritsched(int inheritsched)rnrn switch(inheritsched)rn rn case PTHREAD_INHERIT_SCHED:rn printf("inheritsched is %s\n","INHERIT");rn break;rn case PTHREAD_EXPLICIT_SCHED:rn printf("inheritsched is %s\n","EXPLICIT");rn break;rn default:rn printf("Error:unknown optional.\n");rn break;rn rn rnstatic void display_thread_sched_attr(char *msg)rnrn int policy, ret;rn struct sched_param param;rnrn ret = pthread_getschedparam(pthread_self(), &policy, &param);rn if (ret != 0)rn handle_error_en(ret, "pthread_getschedparam");rnrn printf("%s\n", msg);rn display_sched_attr(policy, &param);rnrnrnstatic void * thread_start(void *arg)rnrn //显示线程的调度属性rn display_thread_sched_attr("\nScheduler attributes of new thread:");rn return NULL;rnrn rnint main(int argc, char *argv[])rnrn int ret,inheritsched,policy;rn pthread_t tid;rn pthread_attr_t attr;rn struct sched_param param;rnrn param.sched_priority = 10; rn policy = SCHED_FIFO;rn ret = pthread_setschedparam(pthread_self(), policy, &param);rn if (ret != 0)rn handle_error_en(ret,"pthread_setschedparam"); rn display_thread_sched_attr("Scheduler settings of main thread:");rn printf("\n");rnrn //初始化线程属性rn ret = pthread_attr_init(&attr);rn if (ret != 0)rn handle_error_en(ret, "pthread_attr_init"); rn rn //设置继承调度属性 rn inheritsched = PTHREAD_EXPLICIT_SCHED;rn //inheritsched = PTHREAD_INHERIT_SCHED; rn ret = pthread_attr_setinheritsched(&attr, inheritsched);rn if (ret != 0)rn handle_error_en(ret, "pthread_attr_setinheritsched"); rn rn //设置线程优先级 rn param.sched_priority = 12;rn ret = pthread_attr_setschedpolicy(&attr, policy);rn if (ret != 0)rn handle_error_en(ret, "pthread_attr_setschedpolicy"); rn ret = pthread_attr_setschedparam(&attr, &param);rn if (ret != 0)rn handle_error_en(ret, "pthread_attr_setschedparam");rnrn //获得线程调度属性 rn ret = pthread_attr_getschedparam(&attr, &param);rn if (ret != 0)rn handle_error_en(ret, "pthread_attr_getschedparam"); rn printf("scheduling parameter attributes:\n");rn display_sched_attr(policy, &param); rn rn //获得线程继承调度属性rn ret = pthread_attr_getinheritsched(&attr, &inheritsched); rn if (ret != 0)rn handle_error_en(ret, "pthread_attr_getinheritsched");rn printf("\nInherit scheduler attribute:\n");rn display_inheritsched(inheritsched); rnrn //创建线程rn ret = pthread_create(&tid, &attr, &thread_start, NULL);rn if (ret != 0)rn handle_error_en(ret, "pthread_create");rnrn /* Destroy unneeded thread attributes object */rn ret = pthread_attr_destroy(&attr);rn if (ret != 0)rn handle_error_en(ret, "pthread_attr_destroy");rnrn ret = pthread_join(tid, NULL);rn if (ret != 0)rn handle_error_en(ret, "pthread_join");rnrn exit(EXIT_SUCCESS);rnrn上面的程序,gcc -lpthread -o attr attr.c编译后执行报错:thread_setschedparam: Operation not permitted,哪位高手帮忙解决一下,谢谢您 ! 论坛

没有更多推荐了,返回首页