您好我从服务器收到此错误。这是使用隧道连接到外部IP的TCP套接字。从我们的源IP,我们向目标服务器IP,端口发送请求。这是我们提供的有关如何连接的信息。
这是我的客户端代码,用于连接,发送,接收和发送消息。我不确定一件事。我在做HTTP Post的方式。 他们给了我们一个样品请求。这就是它的样子
POST /OKMMISPOS HTTP/5.1
Content-Length: 521
ISA*00*__________*00*__________*ZZ*500000330______*ZZ*731476619______*090303*1414*U*004
--------------这是消息的X12内容------------------------- ------------
private void button1_Click(object sender, EventArgs e)
{
try
{
//create a new client socket ...
string szIPSelected = "127.0.0.1";
int szPort = 57000;
if (textBox1.Text != "")
szIPSelected = textBox1.Text;
if (textBox2.Text != "")
szPort = Int32.Parse(textBox2.Text);
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 to " + szIPSelected + ":" + szPort;
statusStrip1.Refresh();
SendRequest(m_socClient);
toolStripStatusLabel1.Text = "Sending Request to " + 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);
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
}
private void SendRequest(Socket m_socClient)
{
string resource = "/OKMMISPOS";
var header = String.Format("POST {0} HTTP/1.1\r\n", resource);
String body = Query270;
byte[] bodyBytes = Encoding.ASCII.GetBytes(body);
header += "Content-Length: " + (body.Length + 1)+ "\r\n" + "\r\n";
string request = String.Concat(header,body);
textBox3.Text = request;
textBox3.Refresh();
byte[] requestBytes= Encoding.ASCII.GetBytes(request);
m_socClient.Send(requestBytes);
}
我的代码发送类似于他们的请求,但我收到了一个HTTP 400错误请求。在wireshark上,请求使用TCP协议开始。这是wireshark的截图。 HTTP 400。 也不确定这是否是imp,请求从TCP开始,响应以HTTP形式返回 请求
响应