0

I am trying to use an API and I am not getting anywhere. The documention says "The document to fax is written directly to the Request Input Stream in binary format"

I have tried using examples from the web like....

$xSendURL = 'http:/example.com/default.ashx?OPT=SendFax&UserName=johndoe...';

# New data
$data = array('FileData' => '@/DATA/html/sites/support/FAAPI/TEST.TIF');

# Create a connection
$ch = curl_init();

# Setting our options
curl_setopt($ch, CURLOPT_URL, $xSendURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

# Get the response
$response = curl_exec($ch);
curl_close($ch);

But when I check the file that is created on the server the contents of the file is the path that I defined for the $data variable. (@/DATA/html/sites/support/FAAPI/TEST.TIF)

I am very new at php. I looked into php://input and php://outout but I am not sure if that would work.

On the URL that I use to invoke the API I pass the filename, username, and security tokens I am not sure how I would grab the Request Input Stream to upload the file after opening the URL.

Any help is appreciated.

Thanks

4

1 回答 1

0

我会尝试将 file_get_contents() 与专门的流一起使用。它的工作原理如下:

  1. 创建一个“上下文”,它是对如何形成 HTTP 请求的描述:

    • 使用 POST 请求
    • 发送带有 Content-Type: image/tiff 的附加标头
    • 包含 tiff 文件的内容
  2. 使用指定的上下文请求 API URL。

骨架代码:

$data = file_get_contents('/DATA/html/sites/support/FAAPI/TEST.TIF');

$options = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: image/tiff',
        'content' => $data,
    )
);

$context = stream_context_create($options);
$result = file_get_contents($xSendURL, false, $context);
于 2013-05-06T08:50:53.370 回答