2016-02-27 79 views
-1

我發送PNG格式的圖像到我的休息客戶端。 但是,當我在客戶端下載文件並嘗試打開它時,我會收到錯誤。 我相信該文件的標題丟失,但我怎麼能將它們添加到服務器響應?序列化PNG和發送到休息客戶端

On the details of my picture i can see, that the size and so on is missing.

ifstream Stream; 

Stream.open(FullFileName,std::ios::binary); 
string Content, Line; 

if (Stream) 
{ 
    while (getline(Stream,Line)){ 
     Content += Line; 
    } 
} 

Stream.close(); 
Request::request->set_body(Content); 
+0

閱讀二進制文件時,getline是否有意義? –

+0

你會用什麼?如果我不打開二進制閱讀我的代碼只讀取圖像的第一行。 – Cazzador

+0

這是你的代碼問題,也是我自己學習的一個問題。我認爲使用帶有二進制文件的getLine是沒有意義的,因爲「行」可能包含1個字節,或者整個文件,具體取決於它的內容。我通常閱讀標題指定的大小的二進制文件,或者至少以規則大小的塊來讀取。然而,我不是C++方面的專家,因此您或其他人對此有所瞭解,我很好奇。 –

回答

0

周圍搜索後發現,在這一側後post

而我創建的Sequenze。

ifstream *Stream = new ifstream(FullFileName, std::ios::in | std::ios::binary); 

    std::ostringstream *oss = new ostringstream(); 
    *oss << Stream->rdbuf(); 
    string *Content = new string(oss->str()); 

    Stream->close(); 
    Request::request->set_body(*Content); 
相關問題