Php 如何在Craigslist上验证和发布?

Php 如何在Craigslist上验证和发布?,php,mysql,xml,Php,Mysql,Xml,我试图验证我的XML,但没有得到正确的响应,有人告诉我如何验证我的post操作吗?那么,无类别、无位置的批量投递方式是什么 我在Craigslist有一个免费帐户。我使用以下代码: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $name='my username';//$_POST['name']; // Get from form or get from DB one per xml $pass

我试图验证我的XML,但没有得到正确的响应,有人告诉我如何验证我的post操作吗?那么,无类别、无位置的批量投递方式是什么

我在Craigslist有一个免费帐户。我使用以下代码:

<?php error_reporting(E_ALL);    
ini_set('display_errors', '1');   
$name='my username';//$_POST['name']; // Get from form or get from DB one per xml
$password= 'my password';//$_POST['password'];
$id='my account ID';//$_POST['id'];    

$xmlStart='<?xml version="1.0"?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">';
$channelStart='<channel>';
$channelItems='<items>';
$channelItemsEnd='</items>';
$channelAuth='<cl:auth username="'.$name.'"
         password="'.$password.'"
         accountID="'.$id.'"/>';
$channelEnd='</channel>';
$xmlEnd='</rdf:RDF>';
$channelItems .='<rdf:li rdf:resource="$179000 / 3br - 3 Bed/1 Bath Great NE Heights         Locating!! No Bank Qualifying!! Owner Fi (NE Albuquerque)"/>'; 
$items='';       
//set the content type to xml
//header("Content-Type: text/xml");
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody = '<rdf:RDF xmlns="http://purl.org/rss/1.0/"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">';
$xmlBody .= "<XML>";
// Run a select query to get my letest 6 items
// Connect to the MySQL database  
mysql_connect("localhost","root","");
mysql_select_db('new_listing');
//$dynamicList = "";
$sql = mysql_query("SELECT * FROM listing ORDER BY id");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){ 
// Create channel item string  
$channelItems .='';
         $id = $row['id'];
         $name = $row['username'];
         $password= $row['password'];
         $address = $row['address'];
         $Posting_type = $row['posting_type'];
         $category = $row['category'];
         $location = $row['location'];
         $posting_title = $row['posting_title'];
         $specific_loc = $row['specific_loc'];
         $postal = $row['postal_code'];
         $description = $row['description'];
         $reply_to = $row['reply_to'];
         $rent = $row['rent'];
         $sqft = $row['sqft'];
         $bedrooms = $row['bedrooms'];
         $bathrooms = $row['bathrooms'];
         $housing = $row['housing_type'];
         $laundry = $row['laundry'];
         $parking = $row['parking'];
         $wheelchair = $row['wheelchair'];
         $smoking = $row['smoking'];
         $furnished = $row['furnished'];
         $street = $row['street'];
         $cross_street = $row['cross_street'];
         $city = $row['city'];
         $zip_code = $row['zip_code'];
         $date_d = $row['date_d'];
         $time_t = $row['time_t'];
         $image = $row['images'];       
$items .= '
<item rdf:about="real estate">
<cl:category>"housing"</cl:category>
<cl:area>"NE Albuquerque"</cl:area>
<cl:housingInfo price="$179000"
                bedrooms="3"
                sqft="1400"/>
  <cl:replyEmail privacy="C">email address</cl:replyEmail>
  <cl:brokerInfo companyName="Your Company name"
               feeDisclosure="fee disclosure here" />
   <title>"$179000 / 3br - 3 Bed/1 Bath Great NE Heights Locating!! No Bank Qualifying!! Owner Fi (NE Albuquerque)"</title>
    <description><![CDATA["3 Bedroom, 1 Bath 1400sqft home with 1 car garage, 
    Lease With Option To Buy, No Bank Qualifying!! 
    Price $179,000, $1200 lease per month + $15,000 down 
    Great Location in NE Heights close to schools, shopping and jobs!! 
    Very Desirable Location! Call 505-264-7942 and ask for Robert"]]></description>
</item>';
// End while loop
}
mysql_close();
 // close the mysql database connection
//$xmlBody .= "</XML>";
   $xmlToSubmit=$xmlStart.$channelStart.$channelItems.$channelAuth.$channelItemsEnd.$channelEnd.$items.$xmlEnd;

class cURL {

var $headers;
var $user_agent;

function cURL()
{
    $this->headers[] = 'Connection: Keep-Alive';
    $this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
    $this->user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
}



function post($url,$data) {
    $process = curl_init($url);
    curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
    curl_setopt($process, CURLOPT_HEADER, 1);
    curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
    curl_setopt($process, CURLOPT_TIMEOUT, 30);
    curl_setopt($process, CURLOPT_POSTFIELDS, $data);
    curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($process, CURLOPT_POST, 1);
    $return = curl_exec($process);
    $info = curl_getinfo($process);
    curl_close($process);
    return $info;
}

}
 $cc = new cURL();
 $url = 'https://post.craigslist.org/bulk-rss/post';
 $output = $cc->post($url,$xmlToSubmit); 

 //echo $output;

  print_r($output); 
 } ?>

通常,在发布演示代码时,最好删除私人电子邮件地址。我怀疑R.Paulson宁愿他/她的电子邮件地址在代码的一半处没有出现在这里?它有效吗?您可以在提交之前检查这些内容。然后,看看cURL在做什么。你从印刷品中得到了什么?您的CraigsList凭证有效吗?谢谢回复R.Paulson。但它的演示电子邮件地址。是的,我有有效的Craigslist凭证。我的打印结果不正确。请将打印结果编辑到您的问题中。另外,将XML打印到屏幕上,并将其与代码分开添加到问题中。检查是否在浏览器中验证。