美文网首页APP & program
React-Native Fetch (header设置toke

React-Native Fetch (header设置toke

作者: 米亚流年 | 来源:发表于2019-05-18 00:38 被阅读0次

    React native Axios header设置token

    static Axios_post(ori_url, params, bodyParams = '', suffixType) {
          let new_url = this.encodeURL(ori_url, params, suffixType)
          switch (suffixType) {
              case HttpSuffixType.IS_DO:
                  return new Promise((resolve, reject) => {
                      setTimeout(() => {
                          Axios({
                              method: "POST",
                              url: new_url,
                              headers: {
                                  'Content-Type': 'application/json;charset=UTF-8',
                                  'Cookie': 'token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhNWFlMTM4NTE3YTU0OGQ5OGUzZjQzOGQzN2FkZTgwZSIsInNjb3BlIjpbInJlYWQiLCJ3cml0ZSJdLCJnaXJkZXJfdXNlciI6ImE1YWUxMzg1MTdhNTQ4ZDk4ZTNmNDM4ZDM3YWRlODBlX1VTRVJfQUxMT1dFRCIsImV4cCI6MTU1ODEzNjY1NywiYXV0aG9yaXRpZXMiOlsiUk9MRV9VU0VSIl0sImp0aSI6ImRmMmY0NTY1LWQ4NWMtNDFjNC04ZDlmLWEwNjE1MTkyNTBkMCIsImNsaWVudF9pZCI6ImFjbWVfbW9iaWxlIn0.g1DV9JI1mHkH30XGHwXpMejMmY5Y7AyWSZMhUKSNvcHanYZuJBAl5xanrjRIJQlaPoJbQBW-x26kObW-RAvhjpqLTIlAfebhadK4XmdOv3Hp4EMta0th8cRuKWx6-BDy3A-cQGyccgqXPg_JNi3xugfy75o7BZreNLpLVUyY_iilSleBpDZYawfOsJbCf79SBWhpBDMbLY4DPzncq23RdbV-ADd1b_VmaZltCQjrv4GMYDTkHu6zonA9WXm6QNtE2htXLhAcWQ0Ln6_icrAAk2OWMO89YhpXHCQe7q-OlYJq1X2iY2FEd0t61zuNiyAaI_yFhqZyszPCCEQ6WkFXbw'
                              }
                          })
                              .then(ret => {
                                  resolve(ret.data)
                              })
                              .catch(err => {
                                  reject(JSON.stringify(err))
                              })
                      }, 500);
                  })
                  break
              default:
                  return new Promise((resolve, reject) => {
                      setTimeout(() => {
                          this.timeout_fetch(fetch(new_url, {
                              method: 'POST',
                              headers: {
                                  'Connection': 'keep-alive',
                                  'Content-Type': 'application/json',
                              },
                              body: JSON.stringify(""),
                          }))
                              .then(response => response.json())
                              .then(response => {
                                  resolve(response);
                              })
                              .catch((error) => {
                                  reject(error);
                              })
                              .done()
    
                      }, 500);
    
                  })
          }
      }
    
            // axios({
            //     method: "POST",
            //     url: Config.BASE_URL + Config.API_SOME,
            //     headers: {
            //         'Content-Type': 'application/json;charset=UTF-8',
            //         'Cookie': 'token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJhNWFlMTM4NTE3YTU0OGQ5OGUzZjQzOGQzN2FkZTgwZSIsInNjb3BlIjpbInJlYWQiLCJ3cml0ZSJdLCJnaXJkZXJfdXNlciI6ImE1YWUxMzg1MTdhNTQ4ZDk4ZTNmNDM4ZDM3YWRlODBlX1VTRVJfQUxMT1dFRCIsImV4cCI6MTU1ODEzNjY1NywiYXV0aG9yaXRpZXMiOlsiUk9MRV9VU0VSIl0sImp0aSI6ImRmMmY0NTY1LWQ4NWMtNDFjNC04ZDlmLWEwNjE1MTkyNTBkMCIsImNsaWVudF9pZCI6ImFjbWVfbW9iaWxlIn0.g1DV9JI1mHkH30XGHwXpMejMmY5Y7AyWSZMhUKSNvcHanYZuJBAl5xanrjRIJQlaPoJbQBW-x26kObW-RAvhjpqLTIlAfebhadK4XmdOv3Hp4EMta0th8cRuKWx6-BDy3A-cQGyccgqXPg_JNi3xugfy75o7BZreNLpLVUyY_iilSleBpDZYawfOsJbCf79SBWhpBDMbLY4DPzncq23RdbV-ADd1b_VmaZltCQjrv4GMYDTkHu6zonA9WXm6QNtE2htXLhAcWQ0Ln6_icrAAk2OWMO89YhpXHCQe7q-OlYJq1X2iY2FEd0t61zuNiyAaI_yFhqZyszPCCEQ6WkFXbw'
            //     }
            // })
            //     .then(res => {
            //         let i = 0
            //         console.log(res.data)
            //     })
            //     .catch(err => {
            //         let u = 0;
            //         console.log(err)
            //     })
    

    相关文章

      网友评论

        本文标题:React-Native Fetch (header设置toke

        本文链接:https://www.haomeiwen.com/subject/slqzaqtx.html