1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > php curl 表单 外网 在php中使用curl进行表单发布

php curl 表单 外网 在php中使用curl进行表单发布

时间:2021-04-03 16:38:28

相关推荐

php curl 表单 外网 在php中使用curl进行表单发布

嗨,我试图张贴卷曲,但我无法做到这一点

这是我在Csharp中的尝试,它的工作原理,但PHP版本无法正常工作

C#

WebRequest request = WebRequest.Create("/somepage.php");

request.Method = "POST";

request.ContentType = "application/x-www-form-urlencoded";

string postString = "email=email@&dueday=1&duemonth=2&dueyear=3&Submit=Submit";

ASCIIEncoding ascii = new ASCIIEncoding();

byte[] postBytes = ascii.GetBytes(postString.ToString());

request.ContentLength = postBytes.Length;

Stream postStream = request.GetRequestStream();

postStream.Write(postBytes, 0, postBytes.Length);

postStream.Close();

HttpWebResponse response = request.GetResponse() as HttpWebResponse;腓

if (isset($_POST['email']) && trim($_POST['email']) != "") {

//filter out everything but the needed information

$cleanquery = array();

foreach ($_POST as $key=>$value) {

//newsletter name

if (stripos($value, 'something') !== false) {

$cleanquery[$key] = $value;

}

if ($key == 'dueday' || $key == 'duemonth' || $key == 'dueyear' || $key == 'email') {

$cleanquery[$key] = $value;

}

}

$queryline = "";

$i=0;

foreach ($cleanquery as $key=>$value) {

if ($i == 0) {

$queryline .= $key . "=" . $value;

} else {

$queryline .= '&' . $key . '=' . $value;

}

$i++;

}

$url = '/somepage.php';

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_POST,4);

curl_setopt($ch, CURLOPT_POSTFIELDS, $queryline);

curl_exec($ch);

$info = curl_getinfo($ch);

curl_close($ch);

echo $info['http_code'];

}

?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。