The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
7.99k
stars
1.65k
forks
source link
Http exception `Failed to write request body` if request is too big. #1728
Colleagues, hello!
I have problems with using cpprest in my project caused by size of json that I try to send to server.
I realized a small example that indicates the problem:
#!/usr/bin/env python3
from http.server import HTTPServer, BaseHTTPRequestHandler
from socketserver import ThreadingMixIn
import threading
import json
resp = json.dumps({'reply': {'status': 0, 'message': 'OK'}}).encode('utf-8')
print(resp)
class Handler(BaseHTTPRequestHandler):
def do_PUT(self):
content_len = int(self.headers.get('Content-Length'))
print(self.headers)
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.send_header('Content-Length', str(len(resp)))
self.end_headers()
self.wfile.write(resp)
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
def run():
server = ThreadingSimpleServer(('0.0.0.0', 7000), Handler)
server.serve_forever()
if __name__ == '__main__':
run()
So, the exception is thrown...
But! If you reduce the length of dataStrToSend string....
for (int i = 0; i < 1000; i++) dataStrToSend += dataStr;
there are no exceptions.
Also exceptions disappear when you add to server string looking like
self.rfile.read(int(self.headers.get('Content-Length')))
Thanks a lot for your help!
P.S.: As for me it looks like the server is responding before it has received the full request.
The same looking like problem discribed at: https://github.com/dakrone/clj-http/issues/277
Colleagues, hello! I have problems with using cpprest in my project caused by size of json that I try to send to server. I realized a small example that indicates the problem:
That is my server:
So, the exception is thrown...
But! If you reduce the length of dataStrToSend string....
for (int i = 0; i < 1000; i++) dataStrToSend += dataStr;
there are no exceptions.Also exceptions disappear when you add to server string looking like
self.rfile.read(int(self.headers.get('Content-Length')))
Thanks a lot for your help!
P.S.: As for me it looks like the server is responding before it has received the full request. The same looking like problem discribed at: https://github.com/dakrone/clj-http/issues/277