php
  • image
  • curl
  • 2016-06-29 43 views 0 likes 
    0

    我需要你的幫助與多部分/表單數據和捲曲上傳圖像。上傳圖像,捲曲+多部分/表格數據

    我對生成和發送數據的代碼:

     $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"); 
    
         $imageForm = curl_exec($this->_ch); 
    

    ,我必須請求負載:

      ------WebKitFormBoundaryibLm7G5cqxCOuAFy 
          Content-Disposition: form-data; name="file"; filename="1-g-0-032- oz-silver-valcambi-bullion-bar-999-rev.jpg" 
          Content-Type: image/jpeg 
    
          Here appears the souce of the image itself like "ÿØÿàÿØÿàÿØÿàÿØÿàÿØÿàÿØÿà" 
          ------WebKitFormBoundaryibLm7G5cqxCOuAFy 
          Content-Disposition: form-data; name="scrid" 
    
          32482346-7100587438898460646 
          ------WebKitFormBoundaryibLm7G5cqxCOuAFy-- 
    

    我如何獲得圖像的來源? 我試圖獲得源:$imgSource = file_get_contents($filepath),但發送此文本後,服務器返回錯誤417。 如果發送圖像無效的參數,服務器返回帶有錯誤消息的json請求(通常情況下)

    回答

    0

    已解決。 需要在標題中發送Expect: 0

    相關問題