我正在使用 JSONKit.h、JSONKit.m、ios5.1。
我也尝试使用 GET 方法和 POST 发送数据,但我的 django 服务器出错了。
我的代码错了吗?
这是我的代码。
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];
}];
我的 django 服务器收到数据时出错,
raceback(最近一次调用最后):文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”,第86行,运行self.finish_response()文件“/Library /Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”,第 127 行,finish_response Traceback(最近一次调用最后一次):self.write(data)文件“/Library/Frameworks/ Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”,第 86 行,在运行 self.finish_response() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2. 7/wsgiref/handlers.py”,第 210 行,写入 self.send_headers() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”,第 268 行,在 send_headers 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”,第 127 行,在 finish_response self.send_preamble() self.write(data) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2. 7/wsgiref/handlers.py”,第 210 行,写入 self.send_headers() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”,第 268 行,在 send_headers 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”中,第 192 行,在 send_preamble self.send_preamble() 文件中“/Library/Frameworks/Python.framework /Versions/2.7/lib/python2.7/wsgiref/handlers.py",第 192 行,在 send_preamble 'Date: %s\r\n' % format_date_time(time.time()) 回溯(最近一次通话最后): '日期:%s\r\n' % format_date_time(time.time()) 文件 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py”,第 324 行,写入文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ wsgiref/handlers.py”,第 86 行,运行 self.flush() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py”,第 303 行,刷新自我。 _sock.sendall(view[write_offset:write_offset+buffer_size])
错误:[Errno 32] 管道损坏
处理来自 ('127.0.0.1', 54842) 的请求时发生异常 Traceback(最近一次调用最后一次):文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”,第 582 行,在 process_request_thread self.finish_request(request, client_address) 文件 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py",第 323 行,在 finish_request self.RequestHandlerClass(request, client_address, self) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py”,第 139 行,在init super(WSGIRequestHandler, self )。init (*args, **kwargs) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”,第 641 行, self.finish() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”,第 694 行,在完成 self.wfile.flush() 文件“/Library/Frameworks/ Python.framework/Versions/2.7/lib/python2.7/socket.py",第 303 行,刷新 self._sock.sendall(view[write_offset:write_offset+buffer_size])
错误:[Errno 32] 管道损坏
self.finish_response()
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”,第 127 行,finish_response self.write(data) 文件“/Library/Frameworks/Python.framework/ Versions/2.7/lib/python2.7/wsgiref/handlers.py”,第 210 行,写入 self.send_headers() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/ handlers.py”,第 268 行,在 send_headers 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py”,第 324 行,写入 self.flush() 文件“/Library /Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py",第 303 行,刷新 self._sock.sendall(view[write_offset:write_offset+buffer_size])
错误:[Errno 32] 管道损坏
处理来自 ('127.0.0.1', 54843) 的请求时发生异常 Traceback(最近一次调用最后一次):文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”,第 582 行,在 process_request_thread self.finish_request(request, client_address) 文件 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py",第 323 行,在 finish_request self.RequestHandlerClass(request, client_address, self) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py”,第 139 行,在init super(WSGIRequestHandler, self )。init (*args, **kwargs) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”,第 641 行, self.finish() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”,第 694 行,在完成 self.wfile.flush() 文件“/Library/Frameworks/ Python.framework/Versions/2.7/lib/python2.7/socket.py",第 303 行,刷新 self._sock.sendall(view[write_offset:write_offset+buffer_size])
错误:[Errno 32] 管道损坏
self.send_preamble()
文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py”,第 192 行,在 send_preamble 'Date: %s\r\n' % format_date_time(time.time( )) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py”,第 324 行,写入 self.flush() 文件“/Library/Frameworks/Python.framework/Versions /2.7/lib/python2.7/socket.py",第 303 行,刷新 self._sock.sendall(view[write_offset:write_offset+buffer_size])
错误:[Errno 32] 管道损坏
处理来自 ('127.0.0.1', 54844) 的请求时发生异常 Traceback(最近一次调用最后一次):文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”,第 582 行,在 process_request_thread self.finish_request(request, client_address) 文件 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py",第 323 行,在 finish_request self.RequestHandlerClass(request, client_address, self) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/servers/basehttp.py”,第 139 行,在init super(WSGIRequestHandler, self )。init (*args, **kwargs) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”,第 641 行, self.finish() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py”,第 694 行,在完成 self.wfile.flush() 文件“/Library/Frameworks/ Python.framework/Versions/2.7/lib/python2.7/socket.py",第 303 行,刷新 self._sock.sendall(view[write_offset:write_offset+buffer_size])