C++ 使用wxHTTP Post请求上载wxImage

C++ 使用wxHTTP Post请求上载wxImage,c++,wxwidgets,C++,Wxwidgets,如何使用wxHTTP POST请求上载存储在wxImage或wxBitmap中的图像? 我知道我可以通过以下方式实现: wxImage::SaveFile (wxOutputStream &stream, wxBitmapType type) and wxHTTP::SetPostBuffer (const wxString &contentType, const wxMemoryBuffer &data) 但我刚从cpp和wx开始。你就快到了。缺少的部分是实现wxOu

如何使用wxHTTP POST请求上载存储在wxImage或wxBitmap中的图像? 我知道我可以通过以下方式实现:

wxImage::SaveFile (wxOutputStream &stream, wxBitmapType type) and
wxHTTP::SetPostBuffer (const wxString &contentType, const wxMemoryBuffer &data)

但我刚从cpp和wx开始。你就快到了。缺少的部分是实现
wxOutputStream
接口的某个类,然后可以使用
SetPostBuffer()
方法发送其内容

您可以看到
wxOutputStream
的所有提供的实现。看来你在找我

因此,完整的代码部分如下所示:

wxMemoryOutputStream stream;
if (!myImage.SaveFile(stream, wxBITMAP_TYPE_PNG))
    ;// TODO: Handle error
SetPostBuffer("image/png", *stream.GetOutputStreamBuffer());

我就是这样做的。更详细一点,但减去错误检查。。。 成员变量是wxURLs


  // ok now read the data into a buffer again
  wxMemoryBuffer buf;
  {
    // don't have charBuf around for too long
    wxFile f(someFileName);
    char charBuf[f.Length()];
    f.Read(charBuf, f.Length());
    buf.AppendData(charBuf, f.Length());
  }

  // upload!
  wxHTTP post; 

  post.SetPostBuffer("application/gzip", buf);

  post.Connect(mDestUrl.GetServer()):

  wxInputStream *iStream = post.GetInputStream(mDestUrl.GetPath() + "?" + mDestUrl.GetQuery());

  // put result into stream
  wxString res;
  wxStringOutputStream oStream(&res);
  iStream->Read(oStream);

  wxLogDebug(TAG " server replied: " + res);
请注意,wxHttp不执行多部分上载。例如,在PHP中,您可以通过

$postdata = file_get_contents("php://input");