简体   繁体   English

wp_login 钩子不会将发布请求发送到不同的域

[英]wp_login hook does not send post request to different domain

I have hook in wp_login in my WordPress site.我在我的 WordPress 站点中wp_login了 wp_login。 It contains working code which sends a POST request to a different domain.它包含向不同域发送 POST 请求的工作代码。 This code has been tested on a different php server, and with Postman app.此代码已在不同的 php 服务器和 Postman 应用程序上进行了测试。

I have tried to use Code Snippet plugin, and I have tried to use it directly in functions.php file.我曾尝试使用Code Snippet插件,并尝试在functions.php文件中直接使用它。 No luck in both cases.在这两种情况下都没有运气。

Also, I know that it is executed, because if I paste there some invalid code, I will get an exception (inside the function).另外,我知道它被执行了,因为如果我在那里粘贴一些无效代码,我会得到一个异常(在函数内部)。

The thing is that hook in WordPress does not send POST request.问题是 WordPress 中的钩子不发送 POST 请求。 So, I am wondering if WordPress has some settings disallowing it to send requests to different domains?所以,我想知道 WordPress 是否有一些设置不允许它向不同的域发送请求?

Here is the code I tried in Code Snippet and in functions.php :这是我在Code Snippetfunctions.php中尝试的代码:

if ( ! function_exists( 'notifyERP5' ) ) {
function notifyERP5($user_login, $user) {
        $Session = 'test session id';
        $url = 'https://xxx.xxx.xxx.xxx/api/users/setup';
      
        $Id = $user->ID;
    $data = array(  "session" => $Session,
            "username" => $user_login,
            "user_id" => $Id);

        $query = json_encode($data);
        $ch    = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
        $response = curl_exec($ch);
        curl_close($ch);
    
   }
add_action('wp_login', 'notifyERP5', 10, 2);
}

Again: this function was tested in different php server, and with Postman app from different machine, and it works.再次:此 function 在不同的 php 服务器上进行了测试,并与来自不同机器的 Postman 应用程序进行了测试,并且可以正常工作。

Can you give me a hint where to look?你能告诉我在哪里看吗? Why this hook doesn't work at wp_login ?为什么这个钩子在wp_login

With the given configuration of POST request, it will not pass thru if target machine has no SSL certificate, or has a development SSL certificate.使用给定的 POST 请求配置,如果目标机器没有 SSL 证书,或者有开发 SSL 证书,它将不会通过。 Moreover, it has been tested without SSL, and still no luck.而且,在没有SSL的情况下测试过,还是不行。

Conclusion : Target machine has to have valid SSL certificate.结论:目标机器必须具有有效的 SSL 证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM