[新浪微博]response Code=-1011 Request failed: forbidden (403)错误的解决办法

本文详细介绍了在使用AFNetworking框架时遇到的请求失败错误,包括两种常见原因:AFNetworking框架配置问题及新浪对接口访问频率的限制。提供了针对性的解决方案,并解释了如何避免频率限制导致的错误。
写微博项目时,发给新浪的请求经常出错。错误1:

Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)" UserInfo=0x7fddac0ecc00 

这个错误有两种原因:一是可能使用的AFNetWorking框架的问题,创建AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]
加上如下语句:

 mgr.responseSerializer = [AFJSONResponseSerializer serializer];

 mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];

增加支持的数据格式即可;还有一种原因就是新浪不久前对接口的访问频率作了限制,开发调试时稍微频繁点的操作都会被新浪判断为请求频繁,从而导致出现上面的这个错误,目前无解,只有过段时间再访问。

TBC
HotelDetailView.vue:114 GET http://localhost:8080/api/hotels/1/room-types 403 (Forbidden) dispatchXhrRequest @ xhr.js:195 xhr @ xhr.js:15 dispatchRequest @ dispatchRequest.js:51 Promise.then _request @ Axios.js:163 request @ Axios.js:40 Axios.<computed> @ Axios.js:213 wrap @ bind.js:5 fetchHotelDetails @ HotelDetailView.vue:114 (匿名) @ runtime-core.esm-bundler.js:2836 callWithErrorHandling @ runtime-core.esm-bundler.js:199 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:206 hook.__weh.hook.__weh @ runtime-core.esm-bundler.js:2816 flushPostFlushCbs @ runtime-core.esm-bundler.js:385 flushJobs @ runtime-core.esm-bundler.js:427 Promise.then queueFlush @ runtime-core.esm-bundler.js:322 queueJob @ runtime-core.esm-bundler.js:317 effect2.scheduler @ runtime-core.esm-bundler.js:5480 trigger @ reactivity.esm-bundler.js:265 endBatch @ reactivity.esm-bundler.js:323 notify @ reactivity.esm-bundler.js:614 trigger @ reactivity.esm-bundler.js:588 set value @ reactivity.esm-bundler.js:1465 finalizeNavigation @ vue-router.mjs:3503 (匿名) @ vue-router.mjs:3368 Promise.then pushWithRedirect @ vue-router.mjs:3335 push @ vue-router.mjs:3260 navigate @ vue-router.mjs:2315 callWithErrorHandling @ runtime-core.esm-bundler.js:199 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:206 invoker @ runtime-dom.esm-bundler.js:729 api.js:46 Forbidden access - you do not have permission to access this resource. (匿名) @ api.js:46 Promise.then _request @ Axios.js:163 request @ Axios.js:40 Axios.<computed> @ Axios.js:213 wrap @ bind.js:5 fetchHotelDetails @ HotelDetailView.vue:114 (匿名) @ runtime-core.esm-bundler.js:2836 callWithErrorHandling @ runtime-core.esm-bundler.js:199 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:206 hook.__weh.hook.__weh @ runtime-core.esm-bundler.js:2816 flushPostFlushCbs @ runtime-core.esm-bundler.js:385 flushJobs @ runtime-core.esm-bundler.js:427 Promise.then queueFlush @ runtime-core.esm-bundler.js:322 queueJob @ runtime-core.esm-bundler.js:317 effect2.scheduler @ runtime-core.esm-bundler.js:5480 trigger @ reactivity.esm-bundler.js:265 endBatch @ reactivity.esm-bundler.js:323 notify @ reactivity.esm-bundler.js:614 trigger @ reactivity.esm-bundler.js:588 set value @ reactivity.esm-bundler.js:1465 finalizeNavigation @ vue-router.mjs:3503 (匿名) @ vue-router.mjs:3368 Promise.then pushWithRedirect @ vue-router.mjs:3335 push @ vue-router.mjs:3260 navigate @ vue-router.mjs:2315 callWithErrorHandling @ runtime-core.esm-bundler.js:199 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:206 invoker @ runtime-dom.esm-bundler.js:729 HotelDetailView.vue:122 Failed to fetch hotel details or room types: AxiosError {message: 'Request failed with status code 403', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …} fetchHotelDetails @ HotelDetailView.vue:122 await in fetchHotelDetails (匿名) @ runtime-core.esm-bundler.js:2836 callWithErrorHandling @ runtime-core.esm-bundler.js:199 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:206 hook.__weh.hook.__weh @ runtime-core.esm-bundler.js:2816 flushPostFlushCbs @ runtime-core.esm-bundler.js:385 flushJobs @ runtime-core.esm-bundler.js:427 Promise.then queueFlush @ runtime-core.esm-bundler.js:322 queueJob @ runtime-core.esm-bundler.js:317 effect2.scheduler @ runtime-core.esm-bundler.js:5480 trigger @ reactivity.esm-bundler.js:265 endBatch @ reactivity.esm-bundler.js:323 notify @ reactivity.esm-bundler.js:614 trigger @ reactivity.esm-bundler.js:588 set value @ reactivity.esm-bundler.js:1465 finalizeNavigation @ vue-router.mjs:3503 (匿名) @ vue-router.mjs:3368 Promise.then pushWithRedirect @ vue-router.mjs:3335 push @ vue-router.mjs:3260 navigate @ vue-router.mjs:2315 callWithErrorHandling @ runtime-core.esm-bundler.js:199 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:206 invoker @ runtime-dom.esm-bundler.js:729 authStore.js:49 POST http://localhost:8080/api/users/login 403 (Forbidden) dispatchXhrRequest @ xhr.js:195 xhr @ xhr.js:15 dispatchRequest @ dispatchRequest.js:51 Promise.then _request @ Axios.js:163 request @ Axios.js:40 httpMethod @ Axios.js:226 wrap @ bind.js:5 login @ authStore.js:49 wrappedAction @ pinia.mjs:1399 store.<computed> @ pinia.mjs:932 handleLogin @ Auth.vue:219 await in handleLogin cache.<computed>.cache.<computed> @ runtime-dom.esm-bundler.js:1713 callWithErrorHandling @ runtime-core.esm-bundler.js:199 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:206 invoker @ runtime-dom.esm-bundler.js:729 api.js:46 Forbidden access - you do not have permission to access this resource. (匿名) @ api.js:46 Promise.then _request @ Axios.js:163 request @ Axios.js:40 httpMethod @ Axios.js:226 wrap @ bind.js:5 login @ authStore.js:49 wrappedAction @ pinia.mjs:1399 store.<computed> @ pinia.mjs:932 handleLogin @ Auth.vue:219 await in handleLogin cache.<computed>.cache.<computed> @ runtime-dom.esm-bundler.js:1713 callWithErrorHandling @ runtime-core.esm-bundler.js:199 callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:206 invoker @ runtime-dom.esm-bundler.js:729 settle.js:19 Uncaught (in promise) AxiosError {message: 'Request failed with status code 403', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}
06-24
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值