0

私は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サーバーがデータを受信したときのエラー

レースバック(最後の最後の呼び出し):ファイル "/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トレースバック(最後の最後の呼び出し):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'日付:%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])

エラー:[Errno32]壊れたパイプ

('127.0.0.1'、54842)からのリクエストの処理中に例外が発生しましたトレースバック(最後の最後の呼び出し):ファイル "/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行目、finish 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])

エラー:[Errno32]壊れたパイプ

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])

エラー:[Errno32]壊れたパイプ

('127.0.0.1'、54843)からのリクエストの処理中に例外が発生しましたトレースバック(最後の最後の呼び出し):ファイル "/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行目、finish 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])

エラー:[Errno32]壊れたパイプ

self.send_preamble()

ファイル"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py"、行192、send_preamble'日付:%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])

エラー:[Errno32]壊れたパイプ

('127.0.0.1'、54844)からのリクエストの処理中に例外が発生しましたトレースバック(最後の最後の呼び出し):ファイル "/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行目、finish 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])

エラー:[Errno32]壊れたパイプ

4

1 に答える 1

1

自己回答。

GET メソッドは、http 本文にデータを含めることはできません。POST メソッドのみを使用できます。

GET メソッドで情報を送信するには、次のような拡張リクエスト URL を使用します。

"?%@=%@", key, value

サンプル URL は次のとおりです。

http://www.somedomain.com/?name=username&pw=password
于 2012-05-21T03:45:15.577 に答える