首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为了将用户数据发布到应用程序接口,应该在哪里定义xhr.send?

为了将用户数据发布到应用程序接口,应该在哪里定义xhr.send?
EN

Stack Overflow用户
提问于 2020-03-09 01:26:22
回答 1查看 36关注 0票数 0

我的应用程序在reCaptcha验证中失败。剩下的唯一错误如屏幕截图1所示。

有没有人能告诉我这仅仅是没有定义xhr.send变量的问题?如果是这样,那么需要在哪里定义呢?对不起-我不是一个开发人员,只是试图建立我的问题的范围,以继续研究。

屏幕截图1:Error from the Network perspective of my Chrome web developer tool

屏幕截图2:Specific error in my angular.js file with reference to xhr.send

下面是我的captcha验证PHP文件的代码:

代码语言:javascript
运行
复制
    <?php

  $postData = file_get_contents("php://input");
  $request = json_decode($postData);

  header('Access-Control-Allow-Origin: *');

echo json_encode(isValid($request->captchaResponse));
exit;

function isValid($response) {
    try {
        $url = 'https://www.google.com/recaptcha/api/siteverify';
        $data = [
            'secret' => 'mykeyishere',
            'response' => $response
        ];

        $options = [
            'http' => [
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                'method'  => 'POST',
                'content' => http_build_query($data)
            ]
        ];

        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        return json_decode($result);
    }
    catch (Exception $e) {
        return null;
    }
}

?>

根据请求添加头部信息:Header Screenshot

EN

Stack Overflow用户

发布于 2020-03-09 04:11:33

据我所知,你的应用程序不能在Apache web服务器上运行,而是使用基于node.js的web服务器(可能是Express.js),静态文件由Ecstatic static file server middleware提供(这是它自我识别的方式:Node.js v8.15.0/ ecstatic server running @ li1252-85.members.linode.com:8080)。由于它是基于Node的web服务器,它没有配置为正确处理PHP脚本,并且所有PHP脚本都以纯文本形式返回。

这个405 HTTP错误的原因是由于这个基于Node的服务器的配置。对于Express.js,您可以定义要服务的请求方法和路由,其他的将被响应为404 (对于允许的请求方法)或405 (对于不允许的请求方法)。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60590149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档