【问题标题】:php automated post testing [closed]php自动化后期测试[关闭]
【发布时间】:2012-10-20 11:14:06
【问题描述】:

我的站点中有一个页面为 test.php。test.php 的内容如下:

<?php
$testpostvalue=$_POST["testpostvalue"];
chmod("testpost.php", 0755);
$my_file = "testpost.php";
$handle = fopen($my_file, "w") or die("Cannot open file:  ".$my_file);
fwrite($handle, $testpostvalue);
chmod("testpost.php", 0644);
?>

我想从我的本地主机运行以下代码:

<?
$testpostvalue='
<html>
<title>test post</title>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<center>
<style>
body{background-color:#000000;color:#000000;}
</style>
<img src="http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500"</a>
<center>
<body>';


$useragent="Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; Alexa Toolbar; .NET CLR 2.0.50727)";
$url2='http://mysite.com/test.php';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"testpostvalue=".$testpostvalue);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_COOKIEJAR, "COOKIE.txt"); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "COOKIE.txt"); 
$buffer = curl_exec($ch);

但是当我从本地主机运行此代码时,帖子正在更新。但是图像链接存在一些问题。图像链接在 test.php 上显示如下:

<img src=/"http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500"</a>

【问题讨论】:

    标签: php post curl


    【解决方案1】:

    我会先尝试清理 HTML 代码,因为有一些错误,特别是在图像检查周围:

    <html>
    <head>
        <title>test post</title>
        <script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <style>
            body{background-color:#000000;color:#000000;}
        </style>
    </head>
    <body>
        <center>
            <img src="http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500" />
        <center>
    </body>
    </html>
    

    【讨论】:

    • html 部分没有问题。你能给出任何想法,以便图像链接正确显示在输出页面上吗?
    【解决方案2】:

    你的代码工作文件,但我不建议你发送这样的 html 文件尝试

    curl_setopt($ch, CURLOPT_POSTFIELDS,"testpostvalue=". bin2hex($testpostvalue));
    

    还有

    fwrite($handle, pack("H*",$testpostvalue));
    

    【讨论】:

    • 这可能有效,但 curl 不应该是安全的吗?你为什么要建议这个?是一个诚实的问题,需要了解更多。
    • 测试它并看到因为您使用的是CURLOPT_POSTFIELDS .. 带有二进制字符.. 输出可能不符合预期
    • @BABA 我使用了你的第一个建议。但是输出来了?????????????????????????????? ??????????????????????????????????????????????????? ??????????????????????????????????????????????????? ??????????????????????????????????????????????????? ??????????????????????????????????????????????????? ??????????????????????????????????????????????????? ??????????????????????
    • 是的 .. 如果 base64 无法发送正确的结果,那么有些问题是错误的……我也观察到这就是为什么我将其更改为十六进制 @Force Ex
    • thanx,它按预期工作。爸爸,你太棒了:)
    猜你喜欢
    • 2011-05-06
    • 2011-07-21
    • 1970-01-01
    • 2019-07-05
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    相关资源
    最近更新 更多