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

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

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

C#

WebRequest request = WebRequest.Create("http://www.somesite.com/somepage.php");

request.Method = "POST";

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

string postString = "email=email@email.com&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 = 'http://www.somesite.com/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'];

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值