dpbyr64224 2012-12-05 19:59
浏览 142
已采纳

CURL POST显示为put

I am trying to post a request to Amazon MWS Feeds API, and I am using the following 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); 
}       

This outputs the following:

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
)

Why does my request Header show as a Put request when I am setting the POST option?

  • 写回答

1条回答 默认 最新

  • doujiu4643 2012-12-05 23:12
    关注

    When you use the CURLOPT_INFILE option, the method is automatically changed to PUT. I didn't realize that the API I was using requires you to override this operation with CURLOPT_CUSTOMREQUEST = "POST"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度