![](https://csdnimg.cn/release/download_crawler_static/12102307/bg13.jpg)
Java and SOAP
15
POST /LocalWeather HTTP/1.0
Host: www.mindstrm.com
Content-Type: text/xml; charset="utf-8"
Content-Length: 328
SOAPAction: "WeatherStation"
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:GetCurrentTemperature xmlns:m="WeatherStation">
<m:scale>Celsius</m:scale>
</m:GetCurrentTemperature>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The SOAP HTTP request uses the HTTP POST method. Although a SOAP payload could be
transported using some other method such as an HTTP GET, the HTTP binding defined in the
SOAP specification requires the use of the POST method. The POST also specifies the name
of the service being accessed. In the example, we're sending the data to /LocalWeather at the
host specified later in the HTTP header. This tells the server how to route the request within
its own processing space. Finally, our example indicates that we're using HTTP Version 1.0,
although SOAP doesn't require a particular version of HTTP.
The Host: header field specifies the address of the server to which we're sending this request,
www.mindstrm.com. The next header field, Content-Type:, tells the server that we're sending
data using the text/xml media type. All SOAP messages must be sent using text/xml. The
content type in the example also specifies that the data is encoded using the UTF-8 character
set. The SOAP standard doesn't require any particular encoding. Content-Length: tells the
server the character count of the POSTed SOAP XML payload data to follow.
So far, all the headers have been standard HTTP headers that apply to any HTTP POST
messages. The next one, however, is SOAP specific. The SOAPAction: header field is
required for all SOAP request messages transported using HTTP.
2
It provides some
information to the HTTP server in the form of a URI that indicates the intent of the message.
This information is contained in an HTTP header field rather than in the message itself
because it doesn't require the system to process the XML payload first. In turn, this means that
the server can determine if it does not have the information or resources necessary to process
the request without actually parsing the message. Although this field can contain data in any
format or even be empty, the field itself must be present. The header SOAPAction:
"WeatherStation" could indicate that our request requires an active connection to the
weather station located on the roof of the building where the server resides. If the server
knows that the weather station has fallen off the building and was subsequently crushed by
a passing car, it can respond without bothering to process the SOAP payload. This may not be
a common scenario, but the point is that the server can use the URI specified in the
SOAPAction: field to gain some insight into the intent of the message, and act accordingly.
It's also important to know that the URI need not take any particular form. It can be a URL,
a name, a word, or even a number, as long as it has meaning to the server that receives
the message.
2
This is a requirement in SOAP 1.1, but is expected to be optional in SOAP 1.2.