...

View Full Version : Socket help



jmace
12-06-2010, 05:52 PM
I've been trying and trying to get this right. Please, any help would be fantastic.

I am trying to upload a feed file to ebay using the following PHP code:

<?php

$key = "MY_TOKEN_GOES_HERE";

set_time_limit(0);

// GET THE FEED FILE -- this part works
$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 => "me", // 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/pull_feed.php');
curl_setopt_array( $ch, $options );
$contents = curl_exec( $ch );
curl_close( $ch );

//----------------------------------------------------//
// . . . Somewhere in here is the problem. . . . //
//----------------------------------------------------//

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

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

// SEND THE REQUEST
fputs($conn, $request);

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

// CLOSE CONNECTION
fclose($conn);

?>

The $request looks like this:

POST /ws/eBayISAPI.dll?FileExchangeUpload HTTP/1.1
Connection: Keep-Alive
User-Agent: My Client App v1.0
Host: bulksell.ebay.com
Content-Length: 2601
Content-type: multipart/form-data; boundary=THIS_STRING_SEPARATES

--THIS_STRING_SEPARATES
Content-Disposition: form-data; name="token"

MY_TOKEN_GOES_HERE
--THIS_STRING_SEPARATES
Content-Disposition: form-data; name="file"; filename="listings.csv"
Content-Type: text/csv

*Action(SiteID=US|Country=US|Currency=USD|Version=403|CC=UTF-8),"*Category","*Title","Subtitle","*Description","*ConditionID","PicURL","*Quantity","*Format","*StartPrice","BuyItNowPrice","*Duration"
. . . . MORE OF THE FILE . . . .

--THIS_STRING_SEPARATES


The result that I get from ebay is this:

HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Set-Cookie: dp1=bu1p/QEBfX0BAX19AQA**4ede560b^; Domain=.ebay.com; Expires=Wed, 05-Dec-2012 17:51:07 GMT; Path=/ Set-Cookie: s=CgAD4ACBM/nQLYmNjZWYxYmIxMmMwYTIzMzU1NDA3N2EwZmZmZmZjZWJZfmC0; Domain=.ebay.com; Path=/ Set-Cookie: nonsession=CgADKACBWYyQLYmNjZWYxYmIxMmMwYTIzMzU1NDA3N2EwZmZmZmZjZWIAywABTP0pkzGfas7R; Domain=.ebay.com; Expires=Tue, 06-Dec-2011 17:51:07 GMT; Path=/ Cache-Control: private Pragma: no-cache Content-Type: text/html;charset=UTF-8 Content-Length: 755 Date: Mon, 06 Dec 2010 17:51:07 GMT An unknown problem interrupted the file transfer. Please try again.
CloseHTTP/1.1 400 Bad Request Content-Length:54 Connection: close Http/1.1 Bad Request

Any help would be great. I'm really struggling with this one.

Thanks,
jmace

Fumigator
12-06-2010, 08:40 PM
Have you been using the ebay sandbox to test this stuff? Do you get the same results there?

Also what part of the ebay documentation have you been following for this? I tried to find it myself but there's a boatload of different APIs and I'm not sure which one you're using.

jmace
12-08-2010, 10:30 PM
Thanks for the response.

I haven't tried the sandbox. I'm actually not sure where it's located or how to use the it. :o

As for documentation, all I have is this:
http://pics.ebaystatic.com/aw/pics/pdf/us/file_exchange/File_Exchange_Advanced_Instructions.pdf
Starting on page 34

Fumigator
12-09-2010, 04:31 AM
You're putting an actual token in place of the string "MY_TOKEN_GOES_HERE", right?

jmace
12-10-2010, 08:59 PM
Yes, the actual token is there, but I obviously can't show that. If I change the token I get an invalid token message, so I know the token is correct.

Fumigator
12-10-2010, 09:03 PM
OK just making sure...

From here I can't really tell what might be wrong. I suggest going to the sandbox and working it out there. I've done similar POST requests for Paypal and they can be tricky to troubleshoot. Paypal's sandbox has some additional debugging tools that gave me a better picture of what was going on so I was able to find the problem fairly easily. Since Paypal and ebay are the same company, I'd imagine ebay's sandbox has similar debugging tools, which should help you track the problem down.

coremega2002
01-28-2011, 02:33 AM
I found a code snippet online that can upload a csv and send it through the ebay content API. Not sure it this helps.

https://checkout.google.com/view/buy?o=shoppingcart&shoppingcart=827401048812945



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum