Age: 1682
Date: Fri, 10 Jul 2009 14:45:12 GMT
Connection: Keep-Alive
Via: N2.SJC1: 102
ETag: "0a61a4759d6c61:b2f"
Content-Length: 1091
Content-Type: image/gif
Last-Modified: Tue, 12 Sep 2006 10:50:36 GMT
Accept-Ranges: bytes
Server: Microsoft-IIS/6.0
Vary: Accept-Encoding HttpWebRequest test
test.ContentType........
test.Headers........
........~(^@^)~
Date: Fri, 10 Jul 2009 14:45:12 GMT
Connection: Keep-Alive
Via: N2.SJC1: 102
ETag: "0a61a4759d6c61:b2f"
Content-Length: 1091
Content-Type: image/gif
Last-Modified: Tue, 12 Sep 2006 10:50:36 GMT
Accept-Ranges: bytes
Server: Microsoft-IIS/6.0
Vary: Accept-Encoding HttpWebRequest test
test.ContentType........
test.Headers........
........~(^@^)~
个人推荐用WinHttp.
调用那个天气预报 web service 的例子: string requestHeader = null;
string requestBody = null;
requestBody = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n"
+ " <soap:Body>\r\n"
+ " <getWeatherbyCityName xmlns=\"http://WebXml.com.cn/\">\r\n"
+ " <theCityName>" + areaCode + "</theCityName>\r\n"
+ " </getWeatherbyCityName>\r\n"
+ " </soap:Body>\r\n"
+ "</soap:Envelope>";
requestHeader = "POST /WebServices/WeatherWebService.asmx HTTP/1.1\r\n"
+ "Host: www.webxml.com.cn\r\n"
+ "Content-Type: text/xml; charset=utf-8\r\n"
+ "Content-Length: " + requestBody.Length + "\r\n"
+ "SOAPAction: \"http://WebXml.com.cn/getWeatherbyCityName\"\r\n"
+ "Connection: Close\r\n\r\n";
string request = requestHeader + requestBody;
_hevt_socket_closed.Reset();
_rcv_buff = "";
_proxy.Send(_remoteHost, _remotePort, request);
标头加入到Headers集合中
test.Headers.Add(name,value);
..............有些标头名称直接为HttpWebRequest属性.直接赋值即可!
webrequset.headers["名称"]="值"