Hello ! Please tell me what is the error?
The problem is that you need to generate a POST request (multipart / form-data) to upload the image to the server, but after sending it returns 417 error.
------WebKitFormBoundaryibLm7G5cqxCOuAFy Content-Disposition: form-data; name="file"; filename="1-g-0-032-oz-silver-valcambi-bullion-bar-999-rev.jpg" Content-Type: image/jpeg
тело картинки
------WebKitFormBoundaryibLm7G5cqxCOuAFy Content-Disposition: form-data; name="scrid" Content-Disposition: form-data; name="scrid"
32482346-7100587438898460646 ------WebKitFormBoundaryibLm7G5cqxCOuAFy--
My code to generate:
$img = file_get_contents($path); $boundary = '----WebKitFormBoundaryLZI2dppfUIcXxqT0'; $eol = "\r\n"; $postdata = ''; $postdata .= '--'.$boundary.$eol; $postdata .= 'Content-Disposition: form-data; name="scrid"'.$eol.$eol; $postdata .= $scrid.$eol; $postdata .= '--'.$boundary.$eol; $postdata .= 'Content-Disposition: form-data; name="file"; filename="'.$filepath.'"'.$eol; $postdata .= "Content-Type: {$imginfo['mime']}".$eol.$eol; $postdata .= $img.$eol; $postdata .= '--'.$boundary.'--'; $headers = array( "Content-Length: " . strlen($postdata), "Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryLZI2dppfUIcXxqT0", "X-Requested-With: XMLHttpRequest", "Origin:http://www.ebayclassifieds.com", "Accept-Encoding: gzip, deflate", "Accept:application/json, text/javascript, */*;", ); curl_setopt($this->_ch, CURLOPT_URL, 'http://www.ebayclassifieds.com/m/ImageUpload'); curl_setopt($this->_ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($this->_ch, CURLOPT_POST, 1); curl_setopt($this->_ch, CURLOPT_COOKIESESSION, TRUE); curl_setopt($this->_ch, CURLOPT_COOKIEJAR, $this->_cookieFilePath); curl_setopt($this->_ch, CURLOPT_COOKIEFILE, $this->_cookieFilePath); curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->_ch, CURLOPT_REFERER, "http://www.ebayclassifieds.com/m/PostAd?scrid=$scrid"); if curl ( postdata = array('file' => '@'.filepath, 'scrid' => $scrid) ) postdata = array('file' => '@'.filepath, 'scrid' => $scrid) returns 500 errors.
Or can someone tell me if there is a possibility to view the generated request before sending it to the server, in order to compare the response of the browser and the sent request.
Thank!
Headers:
> POST /m/ImageUpload HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36 Host: www.ebayclassifieds.com Referer: http://www.ebayclassifieds.com/m/PostAd?scrid=32482880- 4640459038477850577 Cookie: a=v^Mg!!^e^MTQ2ODQxMjA5MDkxNw!!^i^MjM0NjI4NTU!^u^Ym9oZGFuLWhhbkBtYWlsLnJ1^sec^LTEzMzY4NjQ3MzU!^l^MQ!!^n^aGFuMjAxNg!!^s^YXNVLWNMU1FHT3hlcFZSRGtfTmU4bXEyT25KeFRubzZtQnV2NlFycVkxWQ!!; p=l^birmingham^g^ Content-Length: 39315 Content-Type: multipart/form-data;boundary=---- WebKitFormBoundaryLZI2dppfUIcXxqT0 X-Requested-With: XMLHttpRequest Origin:http://www.ebayclassifieds.com Accept-Encoding: gzip, deflate Accept:application/json, text/javascript, */*; Expect: 100-Continue < HTTP/1.1 417 Expectation Failed < Content-Type: text/html < Content-Length: 363 < Cneonction: close < Date: Wed, 29 Jun 2016 12:14:51 GMT < Server: lighttpd/1.4.28 * HTTP error before end of send, stop sending < * Closing connection 1^ e ^ MTQ2ODQxMjA5MDkxNw !! ^ i ^ MjM0NjI4NTU ^ u ^ Ym9oZGFuLWhhbkBtYWlsLnJ1 ^ sec ^ LTEzMzY4NjQ3MzU ^ l ^ MQ !! ^ n ^ aGFuMjAxNg !! ^ s ^ YXNVLWNMU1FHT3hlcFZSRGtfTmU4bXEyT25KeFRubzZtQnV2NlFycVkxWQ !!;!!> POST /m/ImageUpload HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36 Host: www.ebayclassifieds.com Referer: http://www.ebayclassifieds.com/m/PostAd?scrid=32482880- 4640459038477850577 Cookie: a=v^Mg!!^e^MTQ2ODQxMjA5MDkxNw!!^i^MjM0NjI4NTU!^u^Ym9oZGFuLWhhbkBtYWlsLnJ1^sec^LTEzMzY4NjQ3MzU!^l^MQ!!^n^aGFuMjAxNg!!^s^YXNVLWNMU1FHT3hlcFZSRGtfTmU4bXEyT25KeFRubzZtQnV2NlFycVkxWQ!!; p=l^birmingham^g^ Content-Length: 39315 Content-Type: multipart/form-data;boundary=---- WebKitFormBoundaryLZI2dppfUIcXxqT0 X-Requested-With: XMLHttpRequest Origin:http://www.ebayclassifieds.com Accept-Encoding: gzip, deflate Accept:application/json, text/javascript, */*; Expect: 100-Continue < HTTP/1.1 417 Expectation Failed < Content-Type: text/html < Content-Length: 363 < Cneonction: close < Date: Wed, 29 Jun 2016 12:14:51 GMT < Server: lighttpd/1.4.28 * HTTP error before end of send, stop sending < * Closing connection 1
postdata = array('file' => new CURLFile($filepath), 'scrid' => $scrid)- ilyaplot$img = file_get_contents($filepath)), it returns 417 - Bogdan Gudyma