Hi all,
sorry to dust off this thread. I have a similar problem like mober. Here's my code:
- Code: Select all
// prepare session
Poco::URI uri(backend_url + "/api/update_character_avatar");
Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
// prepare path
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_POST, path, Poco::Net::HTTPRequest::HTTP_1_1);
Poco::Net::HTMLForm form;
form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
form.add("token", sw_token);
form.add("charname", sw_charname);
Poco::Buffer<char> imgBuffer(mImgPtr->size());
mImgPtr->read(imgBuffer.begin(), imgBuffer.end()-imgBuffer.begin());
std::string s(imgBuffer.begin(), mImgPtr->size());
std::ostringstream out;
Poco::Base64Encoder b64enc(out);
b64enc.write(imgBuffer.begin(), imgBuffer.end()-imgBuffer.begin());
b64enc.close();
Poco::Net::StringPartSource *prtsrc = new Poco::Net::StringPartSource(out.str());
form.addPart("imagedata", prtsrc);
std::ostringstream ostr;
form.write(ostr);
req.setContentLength(ostr.str().length());
std::ostream& send = session.sendRequest(req);
form.prepareSubmit(req);
form.write(send);
// get response
Poco::Net::HTTPResponse res;
When I std::cout << ostr.str() I see the information is correct.
This is the request thats being sent like seen by rawcap:
- Code: Select all
/api/update_character_avatar HTTP/1.1
Connection: Close
Content-Length: 26586
Host: localhost:8081
--MIME_boundary_14A13DFB4267111B
Content-Disposition: form-data; name="charname"
MeisterLampe
--MIME_boundary_14A13DFB4267111B
Content-Disposition: form-data; name="token"
za32j3xv73qautzxepdqyedp4
--MIME_boundary_14A13DFB4267111B
Content-Disposition: form-data; name="imagedata"
Content-Type: text/plain
--MIME_boundary_14A13DFB4267111B--
As soon as I comment the line form.addPart("imagedata", prtsrc); so it doesn't add the partsrc the request works fine. But with the additional info I have an unlimited connection to my server (it never finishes) until I quit my program.
I use google's app engine. Here's the output from the appengine logs:
- Code: Select all
ERROR 2012-08-11 23:25:17,480 dev_appserver.py:2910] Exception encountered handling request
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2842, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2708, in _Dispatch
int(self.headers.get('content-length', 0)))
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 353, in CopyStreamPart
bytes = source.read(min(bytes_left, COPY_BLOCK_SIZE))
File "C:\Python27\lib\socket.py", line 380, in read
data = self._sock.recv(left)
error: [Errno 10054] Eine vorhandene Verbindung wurde vom Remotehost geschlossen
INFO 2012-08-11 23:25:17,480 dev_appserver.py:2952] "POST /api/update_character_avatar HTTP/1.1" 500 -
Any idea what might be wrong?
Thanks for your help
