小编Ami*_*eem的帖子

如何在axios中处理401(Authentication Error)并做出反应?

我有一个文件request.js,其中包含axios ajax请求的包装器.我从多个反应组件调用请求函数,当其中一个请求失败时,我想刷新令牌并再次重试所有失败的请求.我可以使用拦截器,但我不知道如何实现它.请帮忙.

request.js

 var client = axios.create({
   baseURL: 'http://192.168.1.3:3000',
     headers: {
     appID: 8,
     version: "1.1.0",
     empID: localStorage.getItem('empID'),
     token: localStorage.getItem('accessToken')
    }
 });

 const request = function(options) {
 const onSuccess = function(response) {
 console.debug('Request Successful!', response);
 return response.data;
 } 
 const onError = function(error) {
    console.error('Request Failed:', error.config);
    if (error.response) {
     console.error('Status:',  error.response.status);
     console.error('Data:',    error.response.data);
     console.error('Headers:', error.response.headers);
    } else {
   console.error('Error Message:', error.message);
 }

  return Promise.reject(error.response || error.message);
 }

 return client(options)
         .then(onSuccess)
         .catch(onError);
         options
 }

 export default request;
Run Code Online (Sandbox Code Playgroud)

javascript token http-status-code-401 reactjs axios

15
推荐指数
5
解决办法
3万
查看次数

使用FormData发送文件时,AJAX POST请求无法在safari中工作

我有一个API在谷歌云服务器上传文件并返回网址.我正在使用jquery ajax进行API调用.我使用FormData()对象包含文件.它在chrome中工作得很好,但是当我在safari中尝试相同时,我得到的错误是无法发布/ my-own-site/link/index.html

这是我的代码

  <form method = "post" enctype = "multipart/form-data" id = "get-cloud-link">
     <input type="file" name = "filename" id = "image-input" accept=".jpg,.png,.jpeg"/>
     <input type="text" name = "tag" value = "iwh" class = "hidden"/>
     <input type="text" name = "empID" value = "" class = "hidden"/>
     <input class = "theme-btn" type="submit" id = "get-cloud-link-btn" value = "Upload"/>
  </form>


  $("form#get-cloud-link").submit(function(e){

       var imageInput = $("#image-input");

     if(imageInput.val() == '' || imageInput.val() == null){
       alert('No image is selected, please select image first');
      } else { …
Run Code Online (Sandbox Code Playgroud)

javascript safari ajax jquery

6
推荐指数
0
解决办法
1247
查看次数

如何使用面向对象技术验证 PHP 中的表单字段

我创建了一个类“validate”来验证两个字段,即“firstname”和“lastname”。它工作不正常,当字段为空时显示错误,但是当我提交包含非空字段的表单时,错误仍然存​​在。如何在表单提交时执行此操作?

 <?php

  class validation {

  public $firstName, $lastName, $errorFirstName = '', $errorLastName = '';

  function __constructor($fName, $lName){
    $this->firstName = $fName;
    $this->lastName = $lName;
  }

  function check(){

      if($_SERVER["REQUEST_METHOD"] == "POST"){
        if(empty($this->firstName)){
        $this->errorFirstName = 'First name is required';
       } else {
        $this->errorFirstName = 'Input is okay';
       }

     if(empty($this->lastName)){
         $this->errorLastName = 'Last name is required';
      }  else {
       $this->errorLastName = 'Input is okay';
      }
    }
   }
  }

 $obj = new validation($_POST['firstname'], $_POST['lastname']);
 $obj->check();
 $errorF = $obj->errorFirstName;
 $errorL = $obj->errorLastName;

 ?>

  <!DOCTYPE html>
  <html …
Run Code Online (Sandbox Code Playgroud)

php forms oop validation

5
推荐指数
1
解决办法
6549
查看次数

如何使用unix套接字连接MySQL?

我想使用 Unix 套接字连接来连接到 MySQL。我不确定如何传递连接字符串中的变量。我在某处读到我也可以使用 Config.FormatDSN 结构来定义值,但我不知道如何。

// Creates a database connection and returns its instance
func Connection() (*sql.DB, error) {
    conn, err := sql.Open("mysql", "username/password@unix(socketpath)/dbname")
    return conn, err
}

Run Code Online (Sandbox Code Playgroud)

mysql go

2
推荐指数
1
解决办法
2554
查看次数

如何在 IIS 反向代理上启用 SSL 卸载

我刚刚通过启用应用程序请求路由 (ARR) 并按照本文编辑 web.config 文件,为 Windows Server 上的 NodeJS 应用程序启用了反向代理:

https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing

现在,一切工作正常,我可以从服务器外部的外部客户端访问在本地主机上运行的 NodeJS 应用程序。我想强制与我刚刚创建的反向代理建立 Https 连接。我该如何实现这一目标?

windows iis reverse-proxy arr

1
推荐指数
1
解决办法
7554
查看次数