用抓包工具抓到如下报文,自己用c socket发送不成功。
------------------------------------------------------------------------------------------------------------
POST /axis/services/AuthClient HTTP/1.1
Host: *.*.*.*:8080
Connection: Keep-Alive
User-Agent: EasySoap++/0.6
Content-Type: text/xml; charset="UTF-8"
SOAPAction: "http://DefaultNamespace#m_string_2"
Content-Length: 696<E:Envelope
xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:A="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s="http://www.w3.org/2001/XMLSchema-instance"
xmlns:y="http://www.w3.org/2001/XMLSchema"
E:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<E:Body>
<m:m_string_2
xmlns:m="http://DefaultNamespace">
<m:in0
s:type="y:string">8080</m:in0>
<m:in1
s:type="y:string">360781102</m:in1>
<m:in2
s:type="y:string">rt9188</m:in2>
<m:in3
s:type="y:string">select * from wistable0 where wisfield000=3607811022242500006 and wisfield037='0'</m:in3>
<m:in4
s:type="y:string">gettable_file</m:in4>
</m:m_string_2>
</E:Body>
</E:Envelope>--------------------------------------------------------------------------------------------------------------Content-Length: 696这个报文长度696是怎么编译出来的?
<E:Envelope
xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
标志<E:Envelope和xmlns之间是回车(\r)+换行(\n)+空格吗?
------------------------------------------------------------------------------------------------------------
POST /axis/services/AuthClient HTTP/1.1
Host: *.*.*.*:8080
Connection: Keep-Alive
User-Agent: EasySoap++/0.6
Content-Type: text/xml; charset="UTF-8"
SOAPAction: "http://DefaultNamespace#m_string_2"
Content-Length: 696<E:Envelope
xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:A="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s="http://www.w3.org/2001/XMLSchema-instance"
xmlns:y="http://www.w3.org/2001/XMLSchema"
E:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<E:Body>
<m:m_string_2
xmlns:m="http://DefaultNamespace">
<m:in0
s:type="y:string">8080</m:in0>
<m:in1
s:type="y:string">360781102</m:in1>
<m:in2
s:type="y:string">rt9188</m:in2>
<m:in3
s:type="y:string">select * from wistable0 where wisfield000=3607811022242500006 and wisfield037='0'</m:in3>
<m:in4
s:type="y:string">gettable_file</m:in4>
</m:m_string_2>
</E:Body>
</E:Envelope>--------------------------------------------------------------------------------------------------------------Content-Length: 696这个报文长度696是怎么编译出来的?
<E:Envelope
xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
标志<E:Envelope和xmlns之间是回车(\r)+换行(\n)+空格吗?
需要计算的
怎么计算出来的?还有构造请求包中包含xmlns:E="http://schemas.xmlsoap.org/soap/envelope/"
这个"http://schemas.xmlsoap.org/soap/envelope/"两个分号也不知道怎么怎么处理。
strSoap += “<E:Envelope ”;
strSoap += "...";
.
strSoap += "</E:Envelope>"长度就是strSoap的长度了,这个长度是整型的,还需要转换成,例如CString s;
s.Format(_T("%d"), nLen);
"http://schemas.xmlsoap.org/soap/envelope/"要加个转义符
\"http://schemas.xmlsoap.org/soap/envelope/\"
那个长度数字值就是请求内容的长度(字节为单位)
给一段例子你就基本明白了:const CString getString(int i)
{
CString s; s.Format(_T("%d"), i); return s;
}////////////////////////////////
CString cnt;
CString psr;
cnt.Append(_T("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"));
cnt.Append(_T("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\r\n"));
cnt.Append(_T("<soap12:Body>\r\n"));
cnt.Append(_T("<CelsiusToFahrenheit xmlns=\"http://tempuri.org/\">\r\n"));
cnt.Append(_T("<Celsius>100</Celsius>\r\n"));
cnt.Append(_T("</CelsiusToFahrenheit>\r\n"));
cnt.Append(_T("</soap12:Body>\r\n"));
cnt.Append(_T("</soap12:Envelope>\r\n\r\n"));
psr.Append(_T("POST "));
psr.Append(_T("/webservices/tempconvert.asmx"));
psr.Append(_T(" HTTP/1.1\r\nHOST: "));
psr.Append(_T("www.w3schools.com"));
psr.Append(_T("\r\nContent-Type: application/soap+xml; charset=utf-8"));
psr.Append(_T("\r\nContent-Length: "));
psr.Append(getString(CStringA(cnt).GetLength()));
psr.Append(_T("\r\n\r\n"));
psr.Append(cnt); CStringA szSendBuff(psr);
int ntetv = send(m_sock, szSendBuff, szSendBuff.GetLength(), 0);
ntetv = GetLastError();
// jxpis.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <winsock2.h>
#include <stdio.h>
#pragma comment(lib,"ws2_32")
char *PisDatas1="POST /axis/services/AuthClient HTTP/1.1\r\n"
"Host: *.*.*.*:8080\r\n"
"Connection: Keep-Alive\r\n"
"User-Agent: EasySoap++/0.6\r\n"
"Content-Type: text/xml; charset=\"UTF-8\"\r\n"
"SOAPAction: \"http://DefaultNamespace#m_string_1\"\r\n";
//"Content-Length: 697\r\n\r\n";
char *PisDatas2=
"<E:Envelope\r\n"
" xmlns:E=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n"
" xmlns:A=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n"
" xmlns:s=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n"
" xmlns:y=\"http://www.w3.org/2001/XMLSchema\"\r\n"
" E:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n"
"<E:Body>\r\n"
"<m:m_string_1\r\n"
" xmlns:m=\"http://DefaultNamespace\">\r\n"
"<m:in0\r\n"
" s:type=\"y:string\">8080</m:in0>\r\n"
"<m:in1\r\n"
" s:type=\"y:string\">360781102</m:in1>\r\n"
"<m:in2\r\n"
" s:type=\"y:string\">rt9188</m:in2>\r\n"
"<m:in3\r\n"
" s:type=\"y:string\">select * from admin</m:in3>\r\n"
"<m:in4\r\n"
" s:type=\"y:string\">gettable_file</m:in4>\r\n"
"</m:m_string_1>\r\n"
"</E:Body>\r\n"
"</E:Envelope>\r\n";void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err; wVersionRequested = MAKEWORD(1,1); err = WSAStartup( wVersionRequested, &wsaData );
if( err != 0)
{
return ;
}
if( LOBYTE( wsaData.wVersion ) != 1 || HIBYTE(wsaData.wVersion) != 1)
{
WSACleanup();
return ;
} SOCKET sockClient = socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr = inet_addr("*.*.*.*");
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons(8080); connect(sockClient,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
//printf("%d\n",strlen(PisDatas2));
char SendDatas[1024];
sprintf(SendDatas, "%sContent-Length: %d\r\n\r\n%s", PisDatas1,strlen(PisDatas2),PisDatas2);
printf("%s",SendDatas);
send(sockClient,SendDatas,strlen(SendDatas)+1,0);
char recvBuf1[1024];
recv(sockClient,recvBuf1,1024,0);
char recvBuf2[4096];
recv(sockClient,recvBuf2,4096,0);
printf("%s\n",recvBuf1);
printf("%s\n",recvBuf2); closesocket(sockClient);
WSACleanup();
}
这里不要加1