鸿蒙js报{"code":200,"data":"request data error"}

wx5b1221fc407ea
发布于 2024-1-8 10:43
浏览
0收藏

鸿蒙js报{“code”:200,“data”:“request data error”}
1.确认后端的json数据没有问题
2.配置config.json

"reqPermissions": [{
        "name": "ohos.permission.INTERNET",
        "reason": "网络http请求"
      }

在module中添加internet权限

{
  "app": {
    "vendor": "example",
    "bundleName": "cyou.guadou.movie",
    "version": {
      "code": 1000000,
      "name": "1.0.0"
    }
  },
  "deviceConfig": {
    "default": {
      "network": {
	"cleartextTraffic": true
      }
    }
  },
  "module": {
    "reqPermissions": [{
        "name": "ohos.permission.INTERNET",
        "reason": "网络http请求"
      }
    ],
    "mainAbility": ".MainAbility",
    "deviceType": [
      "phone"
    ],
    "abilities": [
      {
        "skills": [
          {
            "entities": [
              "entity.system.home"
            ],
            "actions": [
              "action.system.home"
            ]
          }
        ],
        "orientation": "unspecified",
        "visible": true,
        "srcPath": "MainAbility",
        "name": ".MainAbility",
        "srcLanguage": "js",
        "icon": "$media:icon",
        "description": "$string:MainAbility_desc",
        "formsEnabled": false,
        "label": "$string:MainAbility_label",
        "type": "page",
        "launchType": "standard"
      },
      {
        "name": ".DataDefault",
        "srcLanguage": "js",
        "srcPath": "DataDefault",
        "icon": "$media:icon",
        "description": "$string:DataDefault_desc",
        "type": "data",
        "uri": "dataability://cyou.guadou.movie.DataDefault"
      }
    ],
    "distro": {
      "moduleType": "entry",
      "installationFree": false,
      "deliveryWithInstall": true,
      "moduleName": "entry"
    },
    "package": "cyou.guadou.movie",
    "name": ".entry",
    "js": [
      {
        "pages": [
          "pages/index/index",
          "pages/default/default"
        ],
        "name": ".MainAbility",
        "window": {
          "designWidth": 720,
          "autoDesignWidth": false
        }
      }
    ],
    "defPermissions": [
      {
        "name": "cyou.guadou.movie.DataAbilityShellProvider.PROVIDER"
      }
    ]
  }
}

4.仍然报错

{"code":200,"data":"request data error"}

5.发现用的是https网络,所以去除network的"cleartextTraffic": true字段,发现可以正常请求了

01-08 10:32:45.993 28809-28856/cyou.guadou.movie I 03B00/JSApp: app Log: 网络Result:{"code":200,"msg":"success","result":[{"actor":"刘德华 梁朝伟 香港电影 香港 庄文强 犯罪 2022 电影","from":"中国香港","img":"https://cdn1.imgdb.cc/photo/p26/p2651367477.jpg","score":"6.5","time":"2021-09-16","title":"金手指","url":"https://xunlei8.cc/movie/13869275.html","year":"2021"},{"actor":"剧情 犯罪","from":"中国大陆","img":"https://cdn1.imgdb.cc/photo/p29/p2901336439.jpg","score":"5.9","time":"2023-07-31","title":"热搜","url":"https://xunlei8.cc/movie/07802775.html","year":"2023"},{"actor":"剧情 喜剧 家庭","from":"中国大陆","img":"https://cdn1.imgdb.cc/photo/p29/p2900172884.jpg","score":"6.4","time":"2023-11-01","title":"无价之宝","url":"https://xunlei8.cc/movie/60607675.html","year":"2023"},{"actor":"剧情 悬疑 惊悚 历史 犯罪 西部","from":"美国","img":"https://cdn1.imgdb.cc/photo/p28/p2897460998.jpg","score":"7.3","time":"2023-05-20","title":"花月杀手 Killers of the Flower Moon","url":"https://xunlei8.cc/movie/455
01-08 10:32:45.993 28809-28856/cyou.guadou.movie I 03B00/JSApp: app Log: 网络code:200

标签
收藏
回复
举报
1条回复
按时间正序
/
按时间倒序
wx661855af1b63e
wx661855af1b63e

没有用

回复
2024-5-11 07:15:18
回复
    相关推荐