我尝试将图像上传到远程Web服务器。我使用了HTMLForm和FilePartSource。我能够成功地将图像上传到本地服务器(即loclhost),但当我尝试在远程服务器上上传时,从远程Web服务器接收到的响应是“需要长度411”。 我尝试设置request.setContentLength(sizeofimagefile),但仍然存在相同的问题。 有谁可以指导我这个问题是什么或者... 以下是我的代码。
HTMLForm htmlform;
htmlform.set("aaaaaa", "bbbbbbb");
htmlform.set("cccccc", "ddddddd");
htmlform.setEncoding(HTMLForm::ENCODING_MULTIPART);
PartSource * pFileSrc = new FilePartSource("filename", "application/octet-stream");
std::istream& mystream = pFileSrc->stream();
mystream.seekg(0, std::ios::end);
int uiLength = mystream.tellg();
htmlform.addPart("file", pFileSrc);
URI uri("yyy");
HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest post_req(Poco::Net::HTTPRequest::HTTP_POST,"xxx",HTTPMessage::HTTP_1_1);
post_req.setKeepAlive(true);
htmlform.prepareSubmit(post_req);
std::ostream& oustr = session.sendRequest(post_req);
htmlform.write(oustr);
HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
std::cerr << rs.rdbuf();
提前感谢你的帮助。