Note that there are some explanatory texts on larger screens.

plurals
  1. POiphone - how to make JSON data for NSMutableURLRequest GET Method
    primarykey
    data
    text
    <p>I'm using JSONKit.h, JSONKit.m, ios5.1.</p> <p>and I tried to send data using GET method and POST also but my django server gave errors.</p> <p>Is my code wrong? </p> <p>here is my codes.</p> <pre><code>NSString *myid = @"myidddd"; NSString *mypw = @"mypwwww"; NSArray *objects = [NSArray arrayWithObjects:myid,mypw, nil]; NSArray *keys = [NSArray arrayWithObjects:@"id", @"pw", nil]; NSDictionary *dic = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; NSString *jsonInfo = [dic JSONString]; NSData *jsonData = [jsonInfo dataUsingEncoding:NSUTF8StringEncoding]; NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"http://www.scg.com:8000/post"]]; [request setHTTPMethod:@"GET"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:[NSString stringWithFormat:@"%d", [jsonData length]] forHTTPHeaderField:@"Content-Length"]; [request setHTTPBody:jsonData]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *res, NSData *data, NSError *err){ [self didReceiveData:data]; }]; </code></pre> <p>Errors when my django server received the data, </p> <p>raceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run self.finish_response() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response Traceback (most recent call last): self.write(data) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run self.finish_response() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 210, in write self.send_headers() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 268, in send_headers File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response self.send_preamble() self.write(data) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 210, in write self.send_headers() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 268, in send_headers File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 192, in send_preamble self.send_preamble() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 192, in send_preamble 'Date: %s\r\n' % format_date_time(time.time()) Traceback (most recent call last): 'Date: %s\r\n' % format_date_time(time.time()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 324, in write File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 86, in run self.flush() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size])</p> <h2>error: [Errno 32] Broken pipe</h2> <p>Exception happened during processing of request from ('127.0.0.1', 54842) Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 582, in process_request_thread self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 139, in <strong>init</strong> super(WSGIRequestHandler, self).<strong>init</strong>(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 641, in <strong>init</strong> self.finish() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 694, in finish self.wfile.flush() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size])</p> <h2>error: [Errno 32] Broken pipe</h2> <pre><code>self.finish_response() </code></pre> <p>File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response self.write(data) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 210, in write self.send_headers() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 268, in send_headers File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 324, in write self.flush() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size])</p> <h2>error: [Errno 32] Broken pipe</h2> <p>Exception happened during processing of request from ('127.0.0.1', 54843) Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 582, in process_request_thread self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 139, in <strong>init</strong> super(WSGIRequestHandler, self).<strong>init</strong>(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 641, in <strong>init</strong> self.finish() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 694, in finish self.wfile.flush() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size])</p> <h2>error: [Errno 32] Broken pipe</h2> <pre><code>self.send_preamble() </code></pre> <p>File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 192, in send_preamble 'Date: %s\r\n' % format_date_time(time.time()) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 324, in write self.flush() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size])</p> <h2>error: [Errno 32] Broken pipe</h2> <p>Exception happened during processing of request from ('127.0.0.1', 54844) Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 582, in process_request_thread self.finish_request(request, client_address) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request self.RequestHandlerClass(request, client_address, self) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 139, in <strong>init</strong> super(WSGIRequestHandler, self).<strong>init</strong>(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 641, in <strong>init</strong> self.finish() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 694, in finish self.wfile.flush() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size])</p> <h2>error: [Errno 32] Broken pipe</h2>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload