Jump to content

Recommended Posts

Hi All,

 

I wrote this code with php curl to do a http post feed to backpage:

 

    $url = "http://posting.newyork.backpage.com/online/BulkUpload/PostAds";

    $filename = "mai_backpage.xml";

 

    $handle = fopen($filename, "r");

    $request = fread($handle, filesize($filename));

    $header[] = "Content-type: application/x-www-form-urlencoded";

    $header[] = "Accept: text/xml";

    $header[] = "Content-length: ".strlen($request);

    $header[] = "Cache-Control: no-cache";

    $header[] = "Connection: close \r\n";

    $header[] = $request;

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,$url);

    curl_setopt($ch, CURLOPT_USERPWD, user@email.com:password');

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_TIMEOUT, 60);

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

    $execPost = curl_exec($ch);

    curl_close($ch);

    echo"$execPost";

    $closefile = fclose($handle);

 

and I've been getting this for reply

 

  <?xml version="1.0" encoding="ISO-8859-1" ?>

- <importResults>

  <userKey />

  <newAdCount>0</newAdCount>

  <updatedAdCount>0</updatedAdCount>

  <creditsUsed>0</creditsUsed>

  <importError>Missing email.</importError>

  <importError>Missing password.</importError>

  <importError>Authentication failed.</importError>

  <importError>Missing file.</importError>

  </importResults>

 

What am I doing wrong that they are not reading the email and password for authentication?

 

Here is the upload documentation from backpage:

http://newyork.backpage.com/online/bulkupload/Documentation

 

Thanks in Advance!

Link to comment
https://forums.phpfreaks.com/topic/64126-php-curl/
Share on other sites

I've read and tried everything but it is just working in php.  It seems to be that the username and password is just not being passed.

 

Below is a perl script that works:

#!c:\perl\bin\perl.exe

    # ^^^ this must be the first line of the script! ^^^

    # start code

   

    use strict;

    use CGI;

    my $q = new CGI;

# print header and start the markup output

   

    print $q->header( "text/html" ),$q->start_html( "backpage response" );

    # end code

 

use Getopt::Long;

use LWP::UserAgent;

use HTTP::Request::Common;

 

  my $server = 'newyork.backpage.com';

 

  # You may choose to hard-code $email and $password here instead

    my $email = 'bpsales';

    my $password = 'bpoffice';

    my $filename = 'backpage.xml';

 

my $ua = LWP::UserAgent->new();

  $ua->agent(qq|Backpage Form Upload Client ($email)|);

 

  my @parameters = ( email => $email,

                  password => $password,

                importFile => [ $filename ],

                    quiet => 'yes' );

 

  my $url = "http://posting.$server/online/BulkUpload/PostAds";

  my $req = POST($url, Content_Type => 'form-data',

                            Content => \@parameters );

  # $req->content_type('multipart/form-data');

  my $response = $ua->request($req);

 

  if ($response->is_success()) {

      my $output = $response->content();

      $output =~ s/^[\s\.]+//; # remove leading whitespace and marching dots

 

      print $output;

  }

  else {

      print "HTTP request failed:\n";

      print $response->status_line() . "\n";

      exit 1;

  }

 

Again anyone see whats missing/wrong with the php script?

Link to comment
https://forums.phpfreaks.com/topic/64126-php-curl/#findComment-325887
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.