POST超时;提取响应待处理

时间:2019-08-12 21:18:53

标签: javascript express post fetch

我试图通过使用Fetch在我的服务器上按一个按钮来使用户能够将数据发送到我的网站,但是请求一直超时,并且出现此错误:

#pragma warning(disable:4996)

#include<stdio.h>

#define N 2

int exist(int matrix[][N], int elem);

void input_matrix(int matrix[][N], int size);


void main()
{
    int matrix_1[][N] = { 0 }, matrix_2[][N] = { 0 }, matrix_3[][N] = { 0 };

    int elem;
    printf("please enter values of squared matrix:\n");
        input_matrix(matrix_1[][N], N);
        //(input_matrix(&matrix_2[N][N]));
    //  (input_matrix(&matrix_3[N][N]));
    printf("please enter number to search for in the matrix:\n");
    scanf("%d", &elem);
    if (exist(matrix_1,elem))
        //printf("exist.");//the next part of h.w to be written when input func works

}

void input_matrix(int matrix[][N], int size)//something here fishy
{
    int i, j;
    for (i = 0; i < size; i++)
    {
        for (j = 0; j < size; j++)
        {
            scanf("%d", &matrix[i][j]);
        }
    }
}
int exist(int matrix[][N], int elem)
{
    int i, j;
    int flag = 0;
    for (i = 0; i < N; i++)
    {
        for (j = 0; j < N; j++)
        {
            if ((matrix[i][j]) == elem)
            {
                flag = 1;
                break;
            }
        }
    }
    return flag;
}

我尝试在服务器端添加app.use(cors()),但这不能解决问题。有什么想法可以解决这个问题吗?

网站上的代码片段:

(index): POST https://www.temp.com:2000/api/folder net::ERR_CONNECTION_TIMED_OUT
(index):1 Uncaught (in promise) TypeError: Failed to fetch

服务器端代码:

var fd = new FormData();
fd.append('data',data);

fetch('https://temp.com:2000/api/folder',{
        method: 'post',
        mode: 'no-cors',
        body: fd
});

1 个答案:

答案 0 :(得分:0)

您的服务器在浏览器等待接收响应时不会将任何响应发送回客户端,因此它会为您提供net :: ERR_CONNECTION_TIMED_OUT

添加一个简单的空响应,例如:

app.post('/api/folder', upload.single('data'), function (req, res) {
   console.log(req.file);
   // we are setting response status code to 200 OK and sending back an empty response
   res.status(200).send();
});