您需要先将字符串转换为流。
你可以简单地用这段代码来完成。
$YourString = 'data-id=2010-10-01_15-15-53';
$stream = fopen('php://memory','r+');
fwrite($stream, $YourString );
$dataLength = ftell($stream);
rewind($stream);
然后有了你的流,你可以使用curl 发送它。
$curl = curl_init();
curl_setopt_array( $curl,
array( CURLOPT_CUSTOMREQUEST => 'PUT'
, CURLOPT_URL => 'https://someurl'
, CURLOPT_HTTPHEADER => array(
'Content-Type: text/plain'
)
, CURLOPT_RETURNTRANSFER => 1 // means output will be a return value from curl_exec() instead of simply echoed
, CURLOPT_TIMEOUT => 15 // max seconds to wait
, CURLOPT_FOLLOWLOCATION => 0 // don't follow any Location headers, use only the CURLOPT_URL, this is for security
, CURLOPT_FAILONERROR => 0 // do not fail verbosely fi the http_code is an error, this is for security
, CURLOPT_SSL_VERIFYPEER => 1 // do verify the SSL of CURLOPT_URL, this is for security
, CURLOPT_VERBOSE => 0 // don't output verbosely to stderr, this is for security
, CURLOPT_INFILE => $stream
, CURLOPT_INFILESIZE => $dataLength
, CURLOPT_UPLOAD => 1
) );
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
echo($response.'<br/>');
echo($http_code.'<br/>');
这应该有效。
下面突出显示了对您有帮助的行:
CURLOPT_INFILE => $stream
CURLOPT_INFILESIZE => $dataLength
CURLOPT_UPLOAD => 1