几乎没有几乎相同的问题,但没有好的答案。我必须将图像发送到 Etsy 端点。
决定使用git 上的lusitanian库。它在内部使用 curl 发出 POST 请求。
不断得到“请求正文太大”的响应。
代码:
$data = [
//'@image' => new \CURLFile($imagePath, $mime, $imageFilename),
'@image' => '@'.$imagePath.';type='.$mime,
];
try {
$response = $etsyService->request(
$this->uri . '/' . $listingId . '/images',
'POST',
$data,
array(
'Content-Type'=>'multipart/form-data'
);
var_dump($response);die;
} catch (\Exception $e) {
var_dump($e->getMessage());
}
内部 lusitanian 使用这个:
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
提出请求。从上面的 $data 都试过了。
有谁知道如何解决这个问题?
编辑:
标头的 var_dump (curl_setopt($ch, CURLINFO_HEADER_OUT, true);)
array (size=27)
'url' => string 'https://openapi.etsy.com/v2/listings/645283994/images' (length=53)
'content_type' => string 'text/plain;charset=UTF-8' (length=24)
'http_code' => int 400
'header_size' => int 895
'request_size' => int 590
'filetime' => int -1
'ssl_verify_result' => int 0
'redirect_count' => int 0
'total_time' => float 0.234278
'namelookup_time' => float 3.9E-5
'connect_time' => float 0.023493
'pretransfer_time' => float 0.083739
'size_upload' => float 105
'size_download' => float 29
'speed_download' => float 123
'speed_upload' => float 448
'download_content_length' => float 29
'upload_content_length' => float 105
'starttransfer_time' => float 0.234254
'redirect_time' => float 0
'redirect_url' => string '' (length=0)
'primary_ip' => string '151.101.13.224' (length=14)
'certinfo' =>
array (size=0)
empty
'primary_port' => int 443
'local_ip' => string '192.168.2.73' (length=12)
'local_port' => int 40466
'request_header' => string 'POST /v2/listings/645283994/images HTTP/1.1
Host: openapi.etsy.com
User-Agent: PHPoAuthLib
Accept: */*
Authorization: OAuth oauth_consumer_key="**************************", oauth_nonce="****************************8", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1542272124", oauth_version="1.0", oauth_token="*************", oauth_signature="******************"
Content-type: multipart/form-data
Connection: close
Content-Length: 105