c# - Error: message[From HTTPUtil::getHttpRequest():Bytes to read is less then ZERO? -
this code sends request server. opening socket using endpoint. have trouble post content length. not using httpwebrequst socket (from our client platform), connects server platform. send 1 long string request.
header = post /okmmis http/5.1 request = header + content content-length = content.length content = @"isa*00* *00* *zz*500000355 *zz*734476619 *130711*1023*^*00501*790719345*0*t*:~gs*hs*500000355*734476619*20130711*1023*273450*x*005010x279a1~st*270*0001*005010x279a1~bht*0022*13*635091349826842989*20130711*1023~hl*1**20*1~nm1*pr*2*oklahoma medicaid*****pi*734476619~hl*2*1*21*1~nm1*1p*2*hillcrest medical center*****xx*1629057229~hl*3*2*22*0~trn*1*20130711102317cdn266905*9cardonhcn~nm1*il*1*messndrew*marquis****mi*b10083667~ref*sy*323006707~dmg*d8*20100108*m~dtp*291*d8*20130512~eq*30~se*14*0001~ge*1*273450~iea*1*790719345~"; the call m_socclient.send(requestbytes) sends message.
their receiving sever logs gives error:
message[from httputil::gethttprequest():bytes read less 0 ???, req->headerlengh 49, req->contentlength 486 , have read 537 bytes
header length = 51. content length= 486. server reads 539 bytes? getting http 400 bad request. response server
http/1.1 400 bad request content-length: 539 post /okmmispos http/5.1 content-length: 486 isa*00* *00* *zz*500000355 *zz*734476619 *130718*1129*^*00501*936078483*0*t*:~gs*hs*500000355*734476619*20130718*1129*326565*x*005010x279a1~st*270*0001*005010x279a1~bht*0022*13*635097437938418629*20130718*1129~hl*1**20*1~nm1*pr*2*oklahoma medicaid*****pi*734476619~hl*2*1*21*1~nm1*1p*2*hillcrest medical center*****xx*1629057229~hl*3*2*22*0~nm1*il*1*marquis*****mi*b17993667~dmg*d8*20101208*m~dtp*291*d8*20130512~eq*30~se*12*0001~ge*1*326565~iea*1*936078483~ where start?
//// create new client socket ... string szipselected = "127.0.0.1"; int szport = 50050; m_socclient = new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp); system.net.ipaddress remoteipaddress = system.net.ipaddress.parse(szipselected); system.net.ipendpoint remoteendpoint = new system.net.ipendpoint(remoteipaddress, szport); m_socclient.connect(remoteendpoint); if (m_socclient.connected) { toolstripstatuslabel1.text = "connected " + szipselected + ":" + szport; statusstrip1.refresh(); string resource = "/okmmispos"; var header = string.format("post {0} http/5.1 " + environment.newline, resource); string body = @"isa*00* *00* *zz*500000355 *zz*734476619 *130711*1023*^*00501*790719345*0*t*:~gs*hs*500000355*734476619*20130711*1023*273450*x*005010x279a1~st*270*0001*005010x279a1~bht*0022*13*635091349826842989*20130711*1023~hl*1**20*1~nm1*pr*2*oklahoma medicaid*****pi*734476619~hl*2*1*21*1~nm1*1p*2*hillcrest medical center*****xx*1629057229~hl*3*2*22*0~trn*1*20130711102317cdn266905*9cardonhcn~nm1*il*1*messndrew*marquis****mi*b10083667~ref*sy*323006707~dmg*d8*20100108*m~dtp*291*d8*20130512~eq*30~se*14*0001~ge*1*273450~iea*1*790719345~"; byte[] bodybytes = encoding.ascii.getbytes(body); header += "content-length: " + (bodybytes.length) + environment.newline + environment.newline + environment.newline; string request = string.concat(header, body); textbox3.text = request; textbox3.refresh(); byte[] requestbytes = encoding.ascii.getbytes(request); m_socclient.send(requestbytes); toolstripstatuslabel1.text = "sending request " + szipselected + ":" + szport; statusstrip1.refresh(); } thread.sleep(3000); byte[] bytes = new byte[1024]; int bytesrec = m_socclient.receive(bytes); txtresponse271.text = encoding.ascii.getstring(bytes, 0, bytesrec); m_socclient.disconnect(true); m_socclient.close();
Comments
Post a Comment