PHP fsockopen 到curl 的转换
我有这段代码:
<?php $host = "registration.mypengo.com";
$request = "/webregistration.aspx?taskaction=serviceresponse&partner=157&subid=" . $subid . "&msisdn=" . $msisdn . "&type=TEXT&data=" . $data . "&serviceid=" . $service_id;
$fp = fsockopen($host, 80, $errno, $errstr, 3.0);
if($fp)
{
fwrite($fp,
"GET $request HTTP/1.0\r\n" .
"Host: $host\r\n".
"Connection: close\r\n".
"Content-Length: " . strlen($request) . "\r\n" .
"\r\n" .
$request);
stream_set_timeout($fp, 2, 0);
$response = "";
while(!feof($fp))
$response .= fread($fp, 1024);
fclose($fp);?>
我想使用curl 尝试一下,但我对curl 有点陌生,所以有人可以分享一些想法吗?
i have this piece of code:
<?php $host = "registration.mypengo.com";
$request = "/webregistration.aspx?taskaction=serviceresponse&partner=157&subid=" . $subid . "&msisdn=" . $msisdn . "&type=TEXT&data=" . $data . "&serviceid=" . $service_id;
$fp = fsockopen($host, 80, $errno, $errstr, 3.0);
if($fp)
{
fwrite($fp,
"GET $request HTTP/1.0\r\n" .
"Host: $host\r\n".
"Connection: close\r\n".
"Content-Length: " . strlen($request) . "\r\n" .
"\r\n" .
$request);
stream_set_timeout($fp, 2, 0);
$response = "";
while(!feof($fp))
$response .= fread($fp, 1024);
fclose($fp);?>
i want to try it out using curl but i am kinda new to curl so can anyone share some ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这与使用 cURL 等效,
顺便说一句,这样制作查询字符串是不安全的。您应该使用
http_build_query()
来构建它,以便正确编码。This is the equivalent using cURL,
BTW, it's not safe to make query string like that. You should use
http_build_query()
to build it so it's properly encoded.我建议你使用这个脚本。这太棒了:
http://www.bin-co.com/php/scripts/load/< /a>
I suggest you to use this script. This is totally awesome:
http://www.bin-co.com/php/scripts/load/