Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Sockets help

  1. #1
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Sockets help

    Hey everyone!

    I am trying to post a feed file to ebay from our site via a PHP script, but I am new to this stuff and having some trouble. On ebay's website they have an example of the request you need to send to post a feed file:
    POST /path/to/upload/script HTTP/1.0
    Connection: Keep-Alive
    User-Agent: My Client App v1.0
    Host:
    https://bulksell.ebay.com/ws/eBayISA...ExchangeUpload
    Content-type: multipart/form-data;
    boundary=THIS_STRING_SEPARATES
    Content-Length: 256
    --THIS_STRING_SEPARATES
    Content-Disposition: form-data; name="token"
    12345678987654321
    --THIS_STRING_SEPARATES
    Content-Disposition: form-data; name="file";
    filename="listings.csv"
    Content-Type: text/csv
    ... contents of listings.csv ...
    --THIS_STRING_SEPARATES

    I tried to implement it using this code:
    PHP Code:
    <?php

    // GET THE FEED FILE
    $options = array(
        
    CURLOPT_RETURNTRANSFER => true,
        
    CURLOPT_HEADER         => false
        
    CURLOPT_FOLLOWLOCATION => true
        
    CURLOPT_ENCODING       => ""
        
    CURLOPT_USERAGENT      => "website"
        
    CURLOPT_AUTOREFERER    => true,
        
    CURLOPT_CONNECTTIMEOUT => 120
        
    CURLOPT_TIMEOUT        => 120,
        
    CURLOPT_MAXREDIRS      => 10
        
    CURLOPT_SSL_VERIFYPEER => false,
    );

    $ch curl_init('https://www.mysite.com/pull_feed.php');
    curl_setopt_array$ch$options );
    $contents curl_exec$ch );
    curl_close$ch );


    //----------------------------------------------------//


    //OPEN THE CONNECTION
    $conn fsockopen('https://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeProgrammaticDownload'80);

    // START THE REQUEST
    fputs($conn"POST ".$_SERVER['PATH_INFO']." HTTP/1.0");
    fputs($conn"Connection: Keep-Alive");
    fputs($conn"User-Agent: My Client App v1.0");
    fputs($conn"Host:");
    fputs($conn"https://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload");
    fputs($conn"Content-type: multipart/form-data;");
    fputs($conn"boundary=THIS_STRING_SEPARATES");
    fputs($conn"Content-Length: ".strlen($contents));
    fputs($conn"--THIS_STRING_SEPARATES");
    fputs($conn"Content-Disposition: form-data; name=\"token\"");
    fputs($conn"MY_KEY_IS_HERE_000000000000000000000000");
    fputs($conn"--THIS_STRING_SEPARATES");
    fputs($conn"Content-Disposition: form-data; name=\"file\";");
    fputs($conn"filename=\"listings.csv\"");
    fputs($conn"Content-Type: text/csv");

    // SEND THE FILE
    fputs($conn$contents);

    // END THE REQUEST
    fputs($conn"--THIS_STRING_SEPARATES");

    // GET THE RESULT
    while(!feof($conn)) {
        echo 
    fgets($conn128);
    }

    // CLOSE CONNECTION
    fclose($conn);

    ?>
    But I am getting this error:
    Warning: fsockopen() [function.fsockopen]: unable to connect to https://bulksell.ebay.com/ws/eBayISA...ticDownload:80 (Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?) in C:\home\imafs\public_html\funad\ebay\send_feed.php on line 27
    Followed by more errors resulting from that one.

    What can I do to solve this? Or is there another way to go about this?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP is configured incorrectly on your server-- or at least it's not configured in the way that you need it.
    Reinstall PHP if you can.

    Create a page with the following line (only) to check your configuration:
    <?php php_info(); ?>

    If you are on a hosting account (rather than your own server) ask your host about this-- they might not allow it (or even block it), or they may be able to install it for you.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,634
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    fsockopen doens't use https. try ssl:// instead.

    supported sockets

  4. The Following User Says Thank You to traq For This Useful Post:

    jmace (11-24-2010)

  5. #4
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    traq was right. That was one of the problems-- possibly the biggest. It's working better now with this code (at least it does something):

    PHP Code:
    <?php

    // GET THE FEED FILE
    $options = array(
        
    CURLOPT_RETURNTRANSFER => true,     // return web page
        
    CURLOPT_HEADER         => false,    // don't return headers
        
    CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        
    CURLOPT_ENCODING       => "",       // handle all encodings
        
    CURLOPT_USERAGENT      => "website"// who am i
        
    CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        
    CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        
    CURLOPT_TIMEOUT        => 120,      // timeout on response
        
    CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        
    CURLOPT_SSL_VERIFYPEER => false,
    );

    $ch curl_init('https://www.mysite.com/pull_feed.php');
    curl_setopt_array$ch$options );
    $contents curl_exec$ch );
    curl_close$ch );


    //----------------------------------------------------//


    //OPEN THE CONNECTION
    $conn fsockopen('ssl://bulksell.ebay.com'443);

    // START THE REQUEST
    fputs($conn"POST ".$_SERVER['PHP_SELF']." HTTP/1.0\r\n");
    fputs($conn"Connection: Keep-Alive\r\n");
    fputs($conn"User-Agent: My Client App v1.0\r\n");
    fputs($conn"Host:\r\n");
    fputs($conn"https://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload\r\n");
    fputs($conn"Content-type: multipart/form-data;\r\n");
    fputs($conn"boundary=THIS_STRING_SEPARATES\r\n");
    fputs($conn"Content-Length: ".strlen($contents)."\r\n");
    fputs($conn"--THIS_STRING_SEPARATES\r\n");
    fputs($conn"Content-Disposition: form-data; name=\"token\"\r\n");
    fputs($conn"MY_SECRET_TOKEN\r\n");
    fputs($conn"--THIS_STRING_SEPARATES\r\n");
    fputs($conn"Content-Disposition: form-data; name=\"file\";\r\n");
    fputs($conn"filename=\"listings.csv\"\r\n");
    fputs($conn"Content-Type: text/csv\r\n\r\n");

    // SEND THE FILE
    fputs($conn$contents."\r\n");

    // END THE REQUEST
    fputs($conn"--THIS_STRING_SEPARATES\r\n");

    // GET THE RESULT
    while(!feof($conn)) {
        echo 
    fgets($conn128);
    }

    // CLOSE CONNECTION
    fclose($conn);

    ?>
    But it is returning:
    HTTP/1.1 302 Moved Temporarily
    Server: Apache-Coyote/1.1
    Location: http://pages.ebay.com/messages/page_....12.13.161.MST
    Date: Wed, 24 Nov 2010 17:12:13 GMT
    Connection: close
    Possibly because I have to connect to ssl://bulksell.ebay.com instead of https://bulksell.ebay.com/ws/eBayISA...mmaticDownload

    You'll notice if you click the link that it's there and waiting for a file, but I'm not sending it there apparently. So now what should I do?

  6. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,634
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    when I click your link I get a 404 page. are you sure this is the correct (and current) url to connect to?

  7. #6
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Did you click this link?
    https://bulksell.ebay.com/ws/eBayISA...mmaticDownload
    Because this definitely is working for me. This is the page I am suppose to go to, from what I understand after reading this:
    http://pics.ebaystatic.com/aw/pics/p...structions.pdf
    (click "using advanced functions", then go to "using programmatic instructions")
    Last edited by jmace; 11-24-2010 at 09:54 PM.

  8. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,634
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Try sending the entire message at once, instead of using fputs() line-by-line.

    (Also, ssl://www.example.com/page and https://www.example.com/page are not different pages; just different protocols.)

  9. #8
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much for your help, traq.

    I understand that ssl:// and https:// are the same page, but the problem is that I cannot connect to
    https://bulksell.ebay.com/ws/eBayISA...mmaticDownload
    directly. I have to connect to page
    bulksell.ebay.com or I get an error:
    Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\home\public_html\send_feed.php on line 28

    Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeProgrammaticDownload:443 (Unknown error) in C:\home\public_html\send_feed.php on line 28

    Warning: fputs(): supplied argument is not a valid stream resource in C:\home\public_html\send_feed.php on line 31

    Warning: fputs(): supplied argument is not a valid stream resource in C:\home\public_html\send_feed.php on line 32

    Warning: fputs(): supplied argument is not a valid stream resource in C:\home\public_html\send_feed.php on line 33

    . . . .
    But bulksell.ebay.com gives me a page not found from the server. . . .
    HTTP/1.1 302 Moved Temporarily
    Server: Apache-Coyote/1.1
    Location: http://pages.ebay.com/messages/page_....07.10.028.MST
    Date: Fri, 26 Nov 2010 17:07:10 GMT
    Connection: close
    I've been told that you have to do the fsockopen() to the domain, instead of the page-- which makes sense seeing as how trying to connect to the page gives me an error. But the domain isn't working either. I have no idea what to do. Any more help would be greatly appreciated.
    Last edited by jmace; 11-26-2010 at 05:10 PM.

  10. #9
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Whoops! I figured out the problem. It was a really stupid mistake on my part. I did in fact have to connect to the domain, not the path. But the
    PHP Code:
    fputs($conn"POST /ws/eBayISAPI.dll?FileExchangeProgrammaticDownload\r\n HTTP/1.1\r\n"); 
    Code was wrong. Fixed now. But now I am getting
    HTTP/1.1 400 Bad Request
    Content-Length:54
    Connection: close

    <html><body><b>Http/1.1 Bad Request</b></body> </html>
    As a response. . . . I'll have to see what's causing that, now.

    Two steps forward, one step back.

  11. #10
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,634
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I don't *think* there's supposed to be a newline between the path and the HTTP declaration.

    Are you still using fputs line-by-line? Try assembling the entire message into a single fputs() call. If ebay is only getting part of your message, they likely just close the connection (that's your "bad request" error) instead of waiting for the whole thing.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •