正在完成以下工作: 1) 客户端使用 API 调用从我们的服务器请求一个 ZIP 文件。2)他在API请求中提供了一个回调url,它是一个aspx程序。3)我们创建ZIP文件,使用php CURL脚本将ZIP文件上传到他的aspx程序中。
问题是,当文件上传到他的服务器上时,ZIP 文件格式会更改(到 SFX Zip 存档)。如果使用简单的 php 脚本将相同的文件上传到我们的服务器,则格式保持不变。我们不确定问题是否与我们使用 CURL 上传文件的方式有关,或者是否与客户端在其服务器上保存 ZIP 文件的方式有关。
CURL 代码如下:
$download_file = "/tmp/test.zip";
$callBackUrl = "http://www.remoteurl/theclients_uploadcode.aspx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => "@$download_file"));
curl_setopt($ch, CURLOPT_URL, $callBackUrl);
curl_exec($ch);
curl_close($ch);
客户端提供了保存数据的aspx代码:
private void SavePost()
{
HttpPostedData = ReadFully(this.Page.Request.InputStream);
Timestamp = DateTime.Now.ToString("MMddyyyy-hhmmss");
Timestamp = Timestamp.Replace("-", "").Replace(" ", "").Replace(":", "");
if (FileName.ToString() == string.Empty)
{
FileName = Timestamp;
}
if (FileName.Contains(".zip") == false)
{
FileName = FileName + ".zip";
}
tempFilePath = (tempFilePath + FileName);
Response.Write((tempFilePath + (" HttpPostedData:" + HttpPostedData)));
}
public static byte[] ReadFully(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
提前致谢。