易趣PHP HTTP POST请求?

时间:2012-03-21 20:12:50

标签: php http-post ebay

亲爱的stackoverflow社区, 目前我正在使用PHP编写文章/客户/计费软件,这是我让合作伙伴对其进行测试之前的最后一步。

我现在真的被困住了。我们想自动将文章上传到易趣。为文件交换程序生成CSV文件工作正常,手动上传也有效,文章将被列出。

现在我们希望软件自行上传。我们参考了易趣文件交换指南herehere

这是我现在的代码:

$SOCKETPROC = fsockopen('bulksell.ebay.de', 80, $errno, $errstr, 4);

fputs($SOCKETPROC, "POST https://bulksell.ebay.de/ws/eBayISAPI.dll?FileExchangeUploadForm HTTP/1.0\r\n");
fputs($SOCKETPROC, "Connection: Keep Alive\r\n");
fputs($SOCKETPROC, "User-Agent: App v1.0\r\n");
fputs($SOCKETPROC, "Host: https://bulksell.ebay.de/ws/eBayISAPI.dll?FileExchangeUpload\r\n");
fputs($SOCKETPROC, "Content-Type: multipart/form-data; boundary=THIS_STRING_SEPARATES\r\n");
fputs($SOCKETPROC, "Content-Length: " . filesize('export/ebay/items-' . date('Y-m-d') . '.csv') + filesize('export/ebay/token') . "\r\n");
fputs($SOCKETPROC, "--THIS_STRING_SEPARATES\r\n");

fputs($SOCKETPROC, "Content-Disposition: form-data; name=\"token\"\r\n");
fputs($SOCKETPROC, file_get_contents('export/ebay/token'));

fputs($SOCKETPROC, "\r\n--THIS_STRING_SEPARATES\r\n");

fputs($SOCKETPROC, "Content-Disposition: form-data; name=\"file\"; filename=\"items-" . date('Y-m-d') . ".csv\"\r\n");
fputs($SOCKETPROC, "Content-Type: text/csv\r\n\r\n");
fputs($SOCKETPROC, file_get_contents('export/ebay/items-' . date('Y-m-d') . '.csv'));

fputs($SOCKETPROC, "\r\n--THIS_STRING_SEPARATES\r\n");
fputs($SOCKETPROC, "Connection: Close\r\n\r\n"); // Not sure if this line is relevant

$RESULT = fgets($SOCKETPROC);
fclose($SOCKETPROC);

但该文件不会出现在上传文件的易趣列表中。当我将https://更改为http://并使用fgets($SOCKETPROC);检查结果时,我得到了HTTP/1.1 200 OK,否则我没有得到任何反应。

如果有人能帮助我,我会非常高兴,最终有人有文件交换计划的经验。绝对乐于接受任何帮助!

提前感谢您阅读我的问题。

注意: .de是故意使用的。所以没有错字或错误; - )

1 个答案:

答案 0 :(得分:1)

尝试通过cUrl连接并上传:

$token = "your_token";
$ebay_url = "https://bulksell.ebay.de/ws/eBayISAPI.dll?FileExchangeUpload";
$sendheaders = array(
"User-Agent: MyClient v1.6",
);
$fields = array(
"token" => $token,
"file" => "@file.csv"
);

$ch = curl_init($ebay_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_NOBODY, 0); // set to 1 to eliminate body info from response
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // use HTTP/1.0 instead of 1.1
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ###
curl_setopt($ch, CURLOPT_HTTPHEADER, $sendheaders);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); // use HTTP POST to send form data
$resp = curl_exec($ch); //execute post and get results
curl_close ($ch);