php curl由于url而失败

时间:2015-10-26 17:16:19

标签: php curl

我编写了一个将一些数据发送到外部服务器的脚本。到目前为止一切正常。问题是当我用变量构建url时,这是必要的,post请求不会成功。当我回应两个变量时,它们完全相同。 $action变量通过数组传递,其值为/index.php?param=value

$regexp = '/<form(.*?)action="(.*?)"(.*?)>(.*?)<\/form>/';
preg_match_all($regexp, $body, $form);

$action = $form[2][0];

$url = 'https://www.homepage.com/index.php?param=value';    // success
$url = 'https://www.homepage.com'.$action;                  // no success

$post_data = array(
        'param1' => 'value1',
        'param2' => 'value2'
);

$data = array(
        'url'       => $url,
        'post_data' => $post_data
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt($ch, CURLOPT_ENCODING, "" );
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEFILE, getcwd () . '/cookie.txt' );
curl_setopt($ch, CURLOPT_COOKIEJAR, getcwd () . '/cookie.txt' );
curl_setopt($ch, CURLOPT_URL, $url);
curl_exec($ch);

没有curl_error($ch)curl_getinfo($ch)我在以下两种情况下都会得到以下内容:

Array
(
    [url] => https://www.homepage.com/index.php?param=value
    [content_type] => text/html; charset=utf-8
    [http_code] => 200
    [header_size] => 437
    [request_size] => 865
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.12154
    [namelookup_time] => 2.1E-5
    [connect_time] => 0.003557
    [pretransfer_time] => 0.014587
    [size_upload] => 468
    [size_download] => 1248
    [speed_download] => 10268
    [speed_upload] => 3850
    [download_content_length] => -1
    [upload_content_length] => 468
    [starttransfer_time] => 0.057372
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 00.00.00.00    // changed by myself
    [certinfo] => Array
        (
        )

    [primary_port] => 443
    [local_ip] => 000.000.000.000    // changed by myself
    [local_port] => 62352
)

修改

我在做什么时

$url_1  = 'https://www.homepage.com/index.php?param=value';    // success
$url_2  = 'https://www.homepage.com'.$action;                  // no success

if ($url_1 == $url_2) {
    echo 'MATCH';
} else {
    echo $url_1.'_';
    echo $url_2.'_';
}

我得到了else语句。所以他们不一样。但他们看起来完全相同。 else语句中的_用于处理空格。

0 个答案:

没有答案
相关问题