Php CURL脚本-POST

Php CURL脚本-POST,php,curl,Php,Curl,我是新来的curl。我只是尝试使用curl脚本发布值,但得到的是空响应。帮帮我,我的密码有错误吗?如何使用curl $params = array('name' => 'karthick', 'type' => 'data'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://example.com/test.php?action=create'); curl_setopt($ch, CURLOPT_RETURNT

我是新来的
curl
。我只是尝试使用
curl
脚本发布值,但得到的是空响应。帮帮我,我的密码有错误吗?如何使用
curl

$params = array('name' => 'karthick', 'type' => 'data'); 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/test.php?action=create');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true );
// curl_setopt($ch, CURLOPT_USERPWD,$authentication);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
// curl_setopt($ch, CURLOPT_REFERER,'http://www.example.com.au');
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain')); 

$result = curl_exec($ch);
curl_close($ch);

var_dump($result);

你可以试试这个代码

public function getDataThroughCurlPost($param)
{ 
    $ch = curl_init("$url");
    error_reporting(E_ALL);
    curl_setopt ($ch, CURLOPT_POST, true);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "$param");

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_NOBODY, 0);

    $response = curl_exec($ch);
    $ch = curl_close("$url");
    return $response;
}

你可以试试这个代码

public function getDataThroughCurlPost($param)
{ 
    $ch = curl_init("$url");
    error_reporting(E_ALL);
    curl_setopt ($ch, CURLOPT_POST, true);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "$param");

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_NOBODY, 0);

    $response = curl_exec($ch);
    $ch = curl_close("$url");
    return $response;
}

我的很多网站都在使用这个。希望这有帮助

$sPost .= "<Username>".$username."</Username>";
$sPost .= "<Password>".$password."</Password>";

$url = "YOUR_POST_URL";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$sPost);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$logindetails = curl_exec($ch);
curl_close($ch);

$xmlarray = xml2array($details);

echo "<pre>"; 
print_r($xmlarray); 
echo "</pre>";
$sPost.=.$username.”;
$sPost.=“.$password.”;
$url=“你的帖子url”;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$sPost);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$logindetails=curl\u exec($ch);
卷曲关闭($ch);
$xmlarray=xml2array($details);
回声“;
打印(xmlarray);
回声“;

xml2array类在这里找到:

我的很多网站都在使用它。希望这有帮助

$sPost .= "<Username>".$username."</Username>";
$sPost .= "<Password>".$password."</Password>";

$url = "YOUR_POST_URL";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$sPost);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$logindetails = curl_exec($ch);
curl_close($ch);

$xmlarray = xml2array($details);

echo "<pre>"; 
print_r($xmlarray); 
echo "</pre>";
$sPost.=.$username.”;
$sPost.=“.$password.”;
$url=“你的帖子url”;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$sPost);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$logindetails=curl\u exec($ch);
卷曲关闭($ch);
$xmlarray=xml2array($details);
回声“;
打印(xmlarray);
回声“;

在此处找到xml2array类:

//curl函数启动

$cont = get_web_page("http://website.com/filename.php");

$handle = explode("<br>",$cont['content']);
print_r($handle);
//旋度函数端

$cont=获取网页(“http://website.com/filename.php");
$handle=explode(“
”,$cont['content']); 打印($handle);
//curl函数启动

$cont = get_web_page("http://website.com/filename.php");

$handle = explode("<br>",$cont['content']);
print_r($handle);
//旋度函数端

$cont=获取网页(“http://website.com/filename.php");
$handle=explode(“
”,$cont['content']); 打印($handle);
您是否先将响应状态设置为200?建议将verbose设置为on,并且您以前是否从该URL获得了正确的响应,例如从命令提示符使用cURL,因为这可能是服务器端问题?现在响应状态为-201:)正常。感谢您的宝贵评论。您是否先获得200的响应状态?建议将verbose设置为on,并且您以前是否从该URL获得了正确的响应,例如从命令提示符使用cURL,因为这可能是服务器端问题?现在响应状态为-201:)正常。感谢您的宝贵评论。请使用错误报告(-1)查找是否有任何错误。还启用了curl吗?嗯…使用错误报告(-1)来找出是否有任何错误。您是否启用了curl?这是我使用此函数的工作代码,请将您的全部代码发送给我code@KarthickV你能解释一下它是如何工作的吗??“我面临着同样的问题,但仍然无法让它正常工作。”哈立德·贾维德——我只是使用了$info=curl\u getinfo($ch);var_dump($info);这是我正在使用此功能的工作代码,请将您的全部信息发送给我code@KarthickV你能解释一下它是如何工作的吗??“我面临着同样的问题,但仍然无法让它正常工作。”哈立德·贾维德——我只是使用了$info=curl\u getinfo($ch);var_dump($info);