【问题标题】:How to log all information going out and coming into CURL?如何记录所有传出和传入 CURL 的信息?
【发布时间】:2017-06-23 10:19:36
【问题描述】:

Client1 向Server1 发送请求并通过php curl 获得响应。我只能访问 Client1 源代码,我需要记录所有发出和进入 Client1 的请求和响应,并将其保存为 txt 文件。

这样做的原因是用新的服务器替换 Server1。 Client1 源代码非常复杂,因此我决定记录所有请求和响应,以便对 Server1 进行逆向工程。

使用 Linux 命令(例如使用 --verbose 和 --trace-ascii)或使用 WireShark 有一些类似问题的答案,但我也无法理解它们,我必须在我的代码中实现它而不是使用命令。该怎么做?

下面是curl函数:

    private function fba8eb($ia61712c)
{
    if (empty($this->v9e19674cb))
        return false;
    $this->query = $ia61712c;
    preg_match('/action=(.*?)&/', $ia61712c, $i43da24755ffd);
    $i87f2ea = $i43da24755ffd[1];
    switch ($this->v488f1ce) {
        case 'no-ssl':
        case 'ssl':
            fwrite($this->v9e19674cb, "POST " . $this->v7d5fd . " HTTP/1.0\r\n");
            fwrite($this->v9e19674cb, "User-Agent: Smsmidlet-api/1.0 (" . $this->v488f1ce . "; " . $this->v9f1e7fea . "; " . $this->v9f1e7fea_version . "; call: $i87f2ea)\r\n");
            fwrite($this->v9e19674cb, "Host: " . $this->v45213b . "\r\n");
            fwrite($this->v9e19674cb, "Content-type: application/x-www-form-urlencoded; charset=utf-8\r\n");
            fwrite($this->v9e19674cb, "Content-length: " . strlen($ia61712c) . "\r\n");
            fwrite($this->v9e19674cb, "\r\n" . $ia61712c . "\r\n");
            $i3bd625bb = '';
            while (!feof($this->v9e19674cb)) {
                @$i3bd625bb .= fgets($this->v9e19674cb, 2048);
            }
            $ie4a1f55ce = fclose($this->v9e19674cb);
            list($ie3dffdbcc, $this->data) = explode("\r\n\r\n", $i3bd625bb, 2);
            return $this->data;
            break;
        case 'curl':
        case 'curl-ssl':
            if (get_resource_type($this->v9e19674cb) == 'curl') {
                @curl_setopt($this->v9e19674cb, CURLOPT_POST, 1);
                @curl_setopt($this->v9e19674cb, CURLOPT_POSTFIELDS, $ia61712c);
                @curl_setopt($this->v9e19674cb, CURLOPT_FOLLOWLOCATION, 1);
                @curl_setopt($this->v9e19674cb, CURLOPT_HEADER, 0);
                @curl_setopt($this->v9e19674cb, CURLOPT_RETURNTRANSFER, 1);
                @curl_setopt($this->v9e19674cb, CURLOPT_SSL_VERIFYPEER, false);
                @curl_setopt($this->v9e19674cb, CURLOPT_USERAGENT, 'Seridlet-api/1.0 (' . $this->v488f1ce . '; ' . $this->v9f1e7fea . '; ' . $this->v9f1e7fea_version . "; call: $i87f2ea )");
                @$i3bd625bb = curl_exec($this->v9e19674cb);
                $i3bd625bb = html_entity_decode($i3bd625bb);
                curl_close($this->v9e19674cb);
                return $this->data = $i3bd625bb;
            }
            break;
    }
    return false;
}

【问题讨论】:

  • 离题:有趣的变量和函数名称。

标签: php curl


【解决方案1】:

也许你可以通过做一个日志功能得到你需要的东西

private function fba8eb($ia61712c)
{
    {
        ob_start();
        var_dump($_GET,$_POST,$_COOKIE,$this,$ia61712c);
        $debugstr=ob_get_clean();
        log_debug_info($debugstr);
        unset($deugstr);
    }
if (empty($this->v9e19674cb))

?

想到的另一件事是 CURLOPT_VERBOSE 和 CURLOPT_STDERR。

代码是否已经在使用 CURLOPT_STDERR?如果没有,您可以创建一个 tmpfile(),将其提供给 CURLOPT_STDERR,启用 CURLOPT_VERBOSE,并在 curl 完成后记录它的内容(请注意,您需要将 stream_get_meta_data($tmpfile)['uri'] 提供给 CURLOPT_STDERR ,而不是文件句柄本身,而是 stream_get_meta_data 为您提供的路径。)

【讨论】:

  • 你的意思是这样的:curl_setopt($ch, CURLOPT_VERBOSE, 1);curl_setopt($ch, CURLOPT_STDERR, $fp);$fp = fopen(dirname(__FILE__).'/log.txt', 'w');
  • 更像curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_STDERR,dirname(__FILE__).'/errorlog.txt'); - PS,如果您运行的是 PHP 5.2 或更早版本,则只需要 dirname(__FILE__)。从 PHP 5.3+ 开始,只需使用 __DIR__ 。但是请注意,如果您有许多 curl 实例同时写入同一日志文件的 stderr,则会出现一些并发问题,但如果没有,我想它很好(不同的 curl 可能开始在彼此中间写入)
  • 我试过了,它返回一些信息,但不返回参数及其值。输出为:* Trying 45.145.143.19... * TCP_NODELAY set * Connected to Seridlet.com (45.145.143.19) port 80 (#0) > POST /api/api.php HTTP/1.1 Host: Seridlet.com User-Agent: Seridlet-api/1.0 (curl; Magento; 1.9.2.4; call: sendinfo ) Accept: */* Content-Length: 255 Content-Type: application/x-www-form-urlencoded * upload completely sent off: 255 out of 255 bytes < HTTP/1.1 200 OK < Date: Fri, 23 Jun 2017 12:19:20 GMT < Server: Apache/2 < Vary: Accept-Encoding ...
猜你喜欢
  • 2014-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-04
  • 1970-01-01
  • 2011-06-23
  • 1970-01-01
相关资源
最近更新 更多