AFNetworking2.0请求数据时出现错误Requestfailed:unacceptablecontent-type:text/html解决方法

本文详细介绍了如何解决使用AFNetworking2.0请求数据时出现的'Requestfailed:unacceptablecontent-type:text/html'错误,通过添加特定代码片段来调整响应序列化类型,确保请求能够正确处理文本HTML格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用AFNetworking 2.0 请求数据时出现错误 Request failed: unacceptable content-type: text/html 解决方法

添加一行

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

即可

整个代码为:

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    NSDictionary *parameters = @{@"foo":@"bar"};
    [manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
    {
        NSLog(@"JSON: %@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
        NSLog(@"Error:%@",error);
    }];


[application] 2025-06-07 17:52:02.341 INFO [21728] [application: platform] [code: 201] [method: POST] [duration: 0] [path: /paas/api/config/get] [url: /paas/api/config/get] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:02.342 INFO [21728] [application: platform] [code: 201] [method: POST] [duration: 3] [path: /paas/api/user/signed] [url: /paas/api/user/signed] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:02.345 INFO [21728] [application: platform] [code: 304] [method: GET] [duration: 2] [path: /paas/api/apps/getInstalledList] [url: /paas/api/apps/getInstalledList] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:02.348 INFO [21728] [application: platform] [code: 201] [method: POST] [duration: 2] [path: /paas/api/system/channel] [url: /paas/api/system/channel] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:02.388 INFO [21728] [application: platform] [code: 304] [method: GET] [duration: 0] [path: /paas/api/apps/isProcessing] [url: /paas/api/apps/isProcessing] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:02.389 INFO [21728] [application: platform] [code: 304] [method: GET] [duration: 3] [path: /paas/api/file/getMyFiles] [url: /paas/api/file/getMyFiles?userId=1&extNames=folder] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:02.391 INFO [21728] [application: platform] [code: 304] [method: GET] [duration: 3] [path: /paas/api/userGroup/getVisibleGroups] [url: /paas/api/userGroup/getVisibleGroups?userId=1] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:02.723 INFO [21728] [application: platform] [code: 304] [method: GET] [duration: 328] [path: /paas/api/apps/getLatestInstalledAppFromSource] [url: /paas/api/apps/getLatestInstalledAppFromSource] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:04.140 INFO [21728] [application: platform] [code: 304] [method: GET] [duration: 0] [path: /paas/api/apps/isProcessing] [url: /paas/api/apps/isProcessing] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:04.250 INFO [21728] [application: platform] [code: 304] [method: GET] [duration: 107] [path: /paas/api/apps/getLatestAllAppFromSource] [url: /paas/api/apps/getLatestAllAppFromSource] [ip: ::1] [refer: http://localhost:3102/workspace.html?appId=appStore] [userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0] [application] 2025-06-07 17:52:06.207 INFO [21728] [安装应用]:mybricks-app-pcspa@1.5.22 安装应用的最新版本:1.5.22 [application] 2025-06-07 17:52:06.211 INFO [21728] [安装应用]:mybricks-app-pcspa@1.5.22 开始下载应用 [application] 2025-06-07 17:52:06.211 INFO [21728] [安装应用]:mybricks-app-pcspa@1.5.22 发现CDN资源,尝试从CDN开始下载 这是我的后台日志,帮我看看有什么问题
06-08
<template> <view class="container"> <!-- 顶部信息展示 --> <view class="header"> <view class="title">{{ formData.dcWjTitle }}</view> <view class="info"> <text>被测评人员:{{ formData.dcName }}</text> <text style="margin-left: 20rpx;">部门:{{ formData.dcDept }}</text> </view> </view> <!-- 其他页面内容 --> </view> </template> <script> export default { data() { return { formData: { dcWjTitle: '加载中...', dcName: '加载中...', dcDept: '加载中...' }, token: '' } }, onLoad(options) { const wjId = options.id console.log('接收到的问卷ID:', wjId) this.getTokenAndLoadData(wjId) }, methods: { async getTokenAndLoadData(id) { try { this.token = uni.getStorageSync('token') if (!this.token) { throw new Error('未找到认证令牌,请重新登录') } await this.loadQuestionnaireData(id) } catch (error) { console.error('获取token失败:', error) uni.showToast({ title: error.message || '请先登录', icon: 'none', duration: 3000 }) setTimeout(() => { uni.reLaunch({ url: '/pages/login/login' }) }, 1500) } }, async loadQuestionnaireData(id) { try { console.log('开始请求问卷数据,ID:', id) // 修复1: 使用正确的URL路径 const response = await uni.request({ url: `http://172.26.26.43/dev-api/wjdc/wj/${id}`, // 注意路径大小写 method: 'GET', header: { 'Authorization': `Bearer ${this.token}` }, timeout: 10000 // 添加超设置 }) // 修复2: 正确处理uni.request返回结构 const [error, result] = response; if (error) { console.error('请求错误:', error) throw new Error(`网络请求失败: ${error.errMsg}`) } // 修复3: 检查状态码和业务码 if (result.statusCode !== 200) { throw new Error(`服务器返回错误状态: ${result.statusCode}`) } // 修复4: 根据接口格式获取数据 const responseData = result.data; if (responseData.code !== 200) { throw new Error(`接口错误: ${responseData.msg || '未知错误'}`) } // 修复5: 正确提取数据 const data = responseData.data console.log('接口返回数据:', data) // 更新表单数据 - 使用实际字段名 this.formData = { dcWjTitle: data.dcWjTitle || '无标题', dcName: data.dcName || '未知人员', dcDept: data.dcDept || '未知部门' } } catch (error) { console.error('请求失败:', error) // 显示错误信息 uni.showToast({ title: error.message || '数据加载失败', icon: 'none', duration: 3000 }) // 更新为错误状态 this.formData = { dcWjTitle: '数据加载失败', dcName: error.message || '请检查网络', dcDept: '或联系管理员' } // 认证错误处理 if (error.message.includes('401') || error.message.includes('认证')) { uni.removeStorageSync('token') setTimeout(() => { uni.reLaunch({ url: '/pages/login/login' }) }, 1500) } } } } } </script> <style scoped> .container { padding: 20rpx; } .header { padding: 30rpx; background-color: #f8f8f8; border-radius: 12rpx; box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.1); margin-bottom: 30rpx; } .title { font-size: 36rpx; font-weight: bold; margin-bottom: 20rpx; color: #333; text-align: center; } .info { display: flex; justify-content: center; font-size: 28rpx; color: #666; } .info text { margin: 0 10rpx; padding: 5rpx 15rpx; background-color: #eef7ff; border-radius: 8rpx; } </style> 报错:17:26:02.824 请求失败:, TypeError: response is not iterable at pages/operation/operation.vue:103
07-24
<template> <view class="container"> <!-- 顶部信息展示 --> <view class="header"> <view class="title">{{ formData.dcWjTitle }}</view> <view class="info"> <text>被测评人员:{{ formData.dcName }}</text> <text style="margin-left: 20rpx;">部门:{{ formData.dcDept }}</text> </view> </view> <!-- 问题展示区域 --> <view class="questions-section"> <view class="section-title">测评结果详情</view> <!--25道单选题 --> <view v-for="(question, index) in questions.slice(0, 25)" :key="index" class="question-item"> <view class="question-content"> <text class="question-number">{{ index + 1 }}.</text> <text>{{ question.content }}</text> </view> <view class="rating-container"> <view class="stars"> <!-- 显示五角星评分 --> <view v-for="star in 5" :key="star" class="star" :class="{ 'filled': star <= formData[question.field], 'active': star <= formData[question.field] }" @tap="setRating(question.field, star)" > ★ </view> </view> <!-- 显示评分文本 --> <text class="rating-text"> {{ ratingTexts[formData[question.field] - 1] }} </text> </view> </view> <!--26道题 - 按分数范围映射到星数 --> <view class="question-item"> <view class="question-content"> <text class="question-number">26.</text> <text>{{ questions[25].content }}</text> </view> <view class="rating-container"> <view class="stars"> <!-- 根据分数范围显示星数 --> <view v-for="star in 5" :key="star" class="star" :class="{ 'filled': star <= starRating26, 'active': star <= starRating26 }" @tap="setScore26(star)" > ★ </view> </view> <!-- 显示评分文本和原始分数 --> <text class="rating-text"> {{ starRatingText26 }} </text> </view> </view> <!--27道题 - 富文本编辑器 --> <view class="question-item"> <view class="question-content"> <text class="question-number">27.</text> <text>{{ questions[26].content }}</text> </view> <view class="editor-container"> <textarea class="textarea" placeholder="请输入意见或建议(支持多行输入)" v-model="formData.no27" uto-height :maxlength="500" placeholder-style="color: #c0c0c0;" @input="handleTextInput" ></textarea> <view class="word-count">{{ (formData.no27 || '').length }}/500</view> </view> </view> </view> <!-- 加载状态指示器 --> <view v-if="loading" class="loading"> <uni-load-more status="loading" :content-text="loadingText"></uni-load-more> </view> <!-- 错误重试面板 --> <view v-if="requestFailed" class="error-panel"> <text>{{ errorMessage }}</text> <button @tap="retryRequest" size="mini" type="primary">重试</button> </view> <!-- 底部按钮区域 --> <view class="bottom-buttons"> <button class="action-button back-button" @tap="goBackToList"> <text>返回列表</text> </button> <button class="action-button submit-button" @tap="handleSubmit" :disabled="isSubmitting" > <text>{{ isSubmitting ? '提交中...' : '提交' }}</text> </button> </view> </view> </template> <style scoped> .container { padding: 20rpx; padding-bottom: 120rpx; /* 为底部按钮留出空间 */ background-color: #f5f7fa; min-height: 100vh; } .header { background-color: #fff; border-radius: 16rpx; padding: 30rpx; margin-bottom: 20rpx; box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05); } .title { font-size: 36rpx; font-weight: bold; color: #333; margin-bottom: 20rpx; text-align: center; } .info { display: flex; justify-content: center; font-size: 28rpx; color: #666; } .info text { background-color: #f0f7ff; padding: 5rpx 15rpx; border-radius: 8rpx; margin: 0 10rpx; } .questions-section { background-color: #fff; border-radius: 16rpx; padding: 30rpx; margin-bottom: 20rpx; box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05); } .section-title { font-size: 32rpx; font-weight: bold; color: #333; padding-bottom: 20rpx; border-bottom: 1rpx solid #eee; margin-bottom: 30rpx; } .question-item { margin-bottom: 40rpx; padding-bottom: 30rpx; border-bottom: 1rpx dashed #eee; } .question-item:last-child { border-bottom: none; } .question-content { display: flex; margin-bottom: 20rpx; font-size: 28rpx; line-height: 1.6; } .question-number { font-weight: bold; min-width: 50rpx; color: #007aff; } .rating-container { display: flex; align-items: center; justify-content: space-between; } .stars { display: flex; } .star { font-size: 40rpx; color: #ccc; margin-right: 15rpx; transition: all 0.2s; cursor: pointer; } .star.filled { color: #ffb400; } .star.active { transform: scale(1.2); } .rating-text { font-size: 24rpx; color: #666; min-width: 180rpx; text-align: right; } .editor-container { border: 1rpx solid #e0e0e0; border-radius: 12rpx; overflow: hidden; margin-top: 20rpx; } .editor { min-height: 300rpx; padding: 20rpx; font-size: 28rpx; } .loading { display: flex; justify-content: center; padding: 40rpx 0; } .error-panel { background-color: #ffebee; border-radius: 12rpx; padding: 30rpx; display: flex; flex-direction: column; align-items: center; margin: 20rpx 0; } .error-panel text { color: #d32f2f; margin-bottom: 20rpx; text-align: center; } .bottom-buttons { position: fixed; bottom: 0; left: 0; right: 0; display: flex; padding: 20rpx; background-color: #fff; box-shadow: 0 -4rpx 12rpx rgba(0, 0, 0, 0.1); } .action-button { flex: 1; height: 90rpx; border-radius: 45rpx; display: flex; align-items: center; justify-content: center; font-size: 32rpx; font-weight: 500; margin: 0 15rpx; transition: all 0.3s; } .back-button { background-color: #f1f1f1; color: #666; } .back-button:active { background-color: #e0e0e0; } .submit-button { background: linear-gradient(to right, #2979ff, #1a68e8); color: #fff; } .submit-button:active { background: linear-gradient(to right, #1a68e8, #0a57d0); } .submit-button[disabled] { background: #a0c0ff; opacity: 0.7; } </style> 我想在顶部的顶部信息展示板块最下面添加一段文字描述:集团公司不会根据回收的问卷去追究任何个人,坦率和自由地表达您的观点对公司的发展是最有帮助的。请从下面题目中选取最能说明您所处的环境和表达您感受的其中一项,请选择对应五角星:
最新发布
07-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值