c# - How to send and receive raw JSON? -



c# - How to send and receive raw JSON? -

i need help determining direction take this. need programme send fixed raw simple json formatted message server @ given ip , port needs hear response on given port , write out raw response console.

i found few topics on doing json http requests don't think on right track. code trying adapt.

public static void send_json() { httpwebrequest request = (httpwebrequest)httpwebrequest.create("http://10.211.55.5:7752"); request.contenttype = "application/json; charset=utf-8"; request.accept = "application/json"; request.method = "post"; using (streamwriter author = new streamwriter(request.getrequeststream())) { writer.write("{\"request\": \"get_menu\", \"checksum\": \"\", \"table_state\": {\"table_id\": \"1\", \"waiter_id\": \"1001\"}}"); } webresponse response = request.getresponse(); stream stream = response.getresponsestream(); string json = ""; using (streamreader reader = new streamreader(stream)) { while (!reader.endofstream) { json += reader.readline(); } console.write(json); } }

the next code ended working! pointing me in right direction guys!

private void pos_test_button_click(object sender, eventargs e) { system.net.sockets.tcpclient clientsocket = new system.net.sockets.tcpclient(); clientsocket.connect("127.0.0.1", 7777); string get_menu_request = "{\"request\": \"get_menu\"}"; networkstream serverstream = clientsocket.getstream(); byte[] outstream = system.text.encoding.ascii.getbytes(get_menu_request); serverstream.write(outstream, 0, outstream.length); serverstream.flush(); byte[] instream = new byte[10025]; serverstream.read(instream, 0, (int)clientsocket.receivebuffersize); string _returndata = system.text.encoding.ascii.getstring(instream); test_log_box.appendtext("\r\n\r\npos connection test: " + "\r\n" + _returndata); }

c# json

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -