2013-04-24 273 views
0

正在執行以下操作: 1)客戶端使用API​​調用從我們的服務器請求ZIP文件。 2)他提供一個回調url,它是API請求中的一個aspx程序。 3)我們創建ZIP文件,使用php CURL腳本將ZIP文件上傳到他的aspx程序中。使用php curl將zip文件上傳到遠程服務器

問題是,當文件上傳到他的服務器上時,ZIP文件格式會更改(SFX Zip存檔)。如果使用簡單的php腳本將相同的文件上傳到我們的服務器,則格式保持不變。我們不確定這個問題與我們使用CURL上傳文件的方式有關,還是與客戶端將ZIP文件保存在其服務器上的方式相同。

捲曲代碼如下:

$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(); 
     } 

    } 

感謝。

回答

0

你保存SavePost不保存任何內容? 您嘗試從this.Page.Request.InputStream中讀取,請參閱FileUpload to FileStream如何轉換它。

btw另請參閱How to read inputstream from HTML file type in C# ASP.NET without using ASP.NET server side control。這說明你也可以使用(c#):

HttpPostedFile file = Request.Files["file"]; 
if (file != null && file.ContentLength) 
{ 
    string fname = Path.GetFileName(file.FileName); 
    file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname))); 
} 
相關問題