1

我正在尝试向 Amazon MWS Feeds API 发布请求,并且我正在使用以下 php:

    private function submit_feed_request($xml)
{
    $feed_handle = @fopen('php://temp', 'rw+');
    fwrite($feed_handle, $xml);
    rewind($feed_handle);
    $md5 = base64_encode(md5(stream_get_contents($feed_handle, true)));
    $options_string = '';
    $count = 0;
    foreach ($this->options as $k => $v)
    {
        $options_string .= rawurlencode($k) . "=" . rawurlencode($v);
        $options_string .= ($count == count($this->options) -1)? '': "&";
        $count++;
    }
    $this->options['PurgeAndReplace'] = false;
    $this->options['Version'] = '2009-01-01';

    $curl_options = array(
            CURLOPT_CAINFO=>$_SERVER['DOCUMENT_ROOT'] . "\public\amazon_api\cacert_pem.crt",
            CURLOPT_RETURNTRANSFER=>true,
            CURLOPT_POST=>1,
            CURLOPT_PORT=>443,
            CURLOPT_POSTFIELDS=> $options_string,
            CURLOPT_SSL_VERIFYHOST=>2,
            CURLOPT_SSL_VERIFYPEER=> TRUE,
            CURLOPT_FOLLOWLOCATION => 1,
            CURLOPT_PROTOCOLS=> CURLPROTO_HTTPS,
            CURLINFO_HEADER_OUT =>true,
            CURLOPT_HTTPHEADER=> array('Content-Type: text/xml','User-Agent: ADS EV 1.0', 'Transfer-Encoding: chunked', 'Host: mws.amazonservices.com', 'Content-MD5: ' . $md5),        
            CURLOPT_INFILE => $feed_handle,
            CURLOPT_UPLOAD=>true,
            //CURLOPT_CUSTOMREQUEST =>'POST_UPLOAD',
            CURLOPT_VERBOSE => true,
            CURLOPT_HEADER =>true,
    );
    $session = curl_init($this->url);
    curl_setopt_array($session, $curl_options);
    $results = curl_exec($session);
    $errors = curl_error($session);
    $info = curl_getinfo($session);
    curl_close($session);
    var_dump($results);
    echo "<br /><br />";
    print_r($info); 
}       

这将输出以下内容:

HTTP/1.1 400 Bad Request
Date: Wed, 05 Dec 2012 19:38:36 GMT
Server: Server
x-mws-request-id: 83644d83-e813-41f3-b6b5-191456798dd8
x-mws-timestamp: 2012-12-05T19:38:37.078Z
x-mws-response-context: vnqPDVXwzbo4KhVB8nJQHAOp1IP8QRp44zAQEwX8G+lNJRHEy6Uawfb87j7Kv5giG/cS2Ov9iZw=
Content-Type: text/xml
Content-Length: 324
Cneonction: close
Vary: Accept-Encoding,User-Agent
nnCoection: close

<?xml version="1.0"?>
<ErrorResponse xmlns="https://mws.amazonservices.com/">
  <Error>
    <Type>Sender</Type>
    <Code>InvalidParameterValue</Code>
    <Message>Either Action or Operation query parameter must be present.</Message>
  </Error>
  <RequestID>83644d83-e813-41f3-b6b5-191456798dd8</RequestID>
</ErrorResponse>
"
<br /><br />Array
(
    [url] => https://mws.amazonservices.com/
    [content_type] => text/xml
    [http_code] => 400
    [header_size] => 424
    [request_size] => 218
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 1.591
    [namelookup_time] => 0.016
    [connect_time] => 0.094
    [pretransfer_time] => 1.342
    [size_upload] => 733
    [size_download] => 324
    [speed_download] => 203
    [speed_upload] => 460
    [download_content_length] => 324
    [upload_content_length] => -1
    [starttransfer_time] => 1.435
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [request_header] => PUT / HTTP/1.1
Accept: */*
Content-Type: text/xml
User-Agent: ADS EV 1.0
Transfer-Encoding: chunked
Host: mws.amazonservices.com
Content-MD5: NTI0YTUwNzgyMTc4OTk4MDIxYTg4YjhjZDRjOGRjZDg=
Expect: 100-continue
)

为什么在设置 POST 选项时,我的请求标头显示为 Put 请求?

4

1 回答 1

0

使用该CURLOPT_INFILE选项时,方法会自动更改为 PUT。我没有意识到我使用的 API 要求您使用CURLOPT_CUSTOMREQUEST = "POST"

于 2012-12-05T23:12:38.650 回答