I'm trying to send a http request to my server created using sockets and try to get the response back. When I'm trying it using the POST man it woks well. But when I try it using the Frisby.js it shows the following error. Here is the code of my server.

    __author__ = 'vimukthi'
import socket
import MySQLdb
import json

mstr = ""
c = ""
data1 = 0
s = ""
con = 0

def myResponse():
    if con == 1:
        print(mstr)
        if mstr == 'GET ':
            response = json.dumps({'200':'OK'})
            message = response.encode('utf-8')
            print(message)
            c.send(message)
        elif mstr == 'POST':
            if data1 == 1:
                response = json.dumps({'status':'2000','desc':'success'})
                message = response.encode('utf-8')
                print(message)
                c.send(message)
            else:
                response = json.dumps({'status':'4001','desc':'id_not_found'})
                message = response.encode('utf-8')
                print(message)
                c.send(message)
        c.close()
    else:
        c.send("No data to display!")
    return

def mySocket():
    global s
    s = socket.socket()
    host = socket.gethostname()
    port = 12345
    s.bind((host, port))
    s.listen(5)
    return

def myMethod():
    mySocket()
    while True:
        global c
        c, addr = s.accept()
        print ('Got connection from', addr)
        request = str(c.recv(addr[1]))
        print(request)
        global mstr
        mstr1 = request.split('\n')[0]
        mstr = mstr1[0:4]
        if mstr == "POST":
            id1 = request.split('\n')[-1]
            method1 = request.split(',')[1]for frisby
            id = id1.split(':')[1]
            msg = method1.split(':')[1]
            print(msg)
            id = id[0] #[1] for postman, [0] for frisby
            print(id)
        elif mstr == "GET ":
            method, message, version = mstr1.split()
            msg = str(message)
            print(mstr)
            print(msg[2:])
            id = msg[5]
            print(id)
        try:
            db = MySQLdb.connect(host='127.0.0.1', user='root', passwd='0112608198', db='dumpDB')
            cur = db.cursor()
            cur.execute("select count(id) from user where id="+id+"")
            value = cur.fetchall()
            data = str(value[0])
            global data1
            data1 = int(data[1])
            print(data1)
            cur.close()
            db.close()
            global con
            con = 1
        except:
            c.send("please try again later")
            con = 0
        myResponse()
    return

myMethod()

Here is my Frisby.js code.

    var frisby = require('/home/vimukthi/Area51/installations/node_modules/frisby');

frisby.create('GET request to my server')
    //.get('http://vimukthi-pc:12345?id=2&method=success')
    .post('http://vimukthi-pc:12345',{"id"  : 1,"method" : "check"},{json:true})
        .inspectJSON()
            .timeout(100000)
.toss()

Can anyone please help me with this issue.

Screen shot of the error.

enter image description here

0

There are 0 answers