System.Net.WebRequest
异常类型:
NotSupportedException
ArgumentNullException
SecurityException
ObjWebRequest.Credentials
如果需要按照特别的验证协议,需要强制转换成HttpWebRequest类型:
ObjWebRequest.Method
=
"POST";
ObjWebRequest.ContentLength
ObjWebRequest.ContentType="application/x-www-form-urlencoded";//Post
ObjWebRequest.ContentType="text/xml";//SOAP
System.IO.Stream
dataStream.Write
(byteArray,
0,
byteArray.Length);
byte[]
byteArray
=
UTF8Encoding.GetBytes(dataP);
dataStream.Close
WebResponse
Objresponse
=
ObjWebRequest.GetResponse();
//Console.WriteLine
if
//..结束这一切
}
Stream
data
=
Objresponse.GetResponseStream
dataStream
StreamReader
Response.Write(HttpUtility.HtmlEncode(r.ReadToEnd()));
Stream
outStream
=System.IO.File.Create(
"Temp.data"
);
byte []buffer
=
new
byte[1024];
int l;
do{
l =
dataStream.Read(buffer,0,buffer.Length);
if(l>0) outStream.Write(buffer,0,l);
} while(l>0);
outStream.Close();
byte
int
do{
l
if(l>0)
}
outStream.Close();
此方式可以保存二进制数据.
Objresponse.Close();
XmlDocument
doc.Load(
HttpWebRequest
req.ContentType
req.Accept
req.Method
Stream
doc.Save(stm);
stm.Close();
WebResponse
stm
StreamReader
Response.Write(HttpUtility.HtmlEncode(r.ReadToEnd()));
Set
xmlhttp.Open
xmlhttp.setRequestHeader
xmlhttp.setRequestHeader
xmlhttp.setRequestHeader
xmlhttp.setRequestHeader
xmlhttp.Send(SoapRequest)
Response.Write
Response.Write
Set
获取的时候:
If
Set
xmlDOC.load(xmlhttp.responseXML)
xmlStr
Set
xmlStr
xmlStr
Response.write
Else
Response.Write
Response.Write
End
请求正确则给出完整响应,请求不正确(如账号,密码不对)响应的内容就会信息不完整.
取出响应里的数据,如下:
If
Set
xmlDOC.load(xmlhttp.responseXML)
Response.Write
Set
Else
Response.Write
Response.Write
End
显示某节点各个属性和数据的FUNCTION:
Function
if
set
nodeAttributelen=myxmlDOC.documentElement.selectSingleNode("//"&rootname&"").attributes.length'当前结点属性数
returnstring=returnstring&"<BR>节点名称:"&rootname
if
returnstring=returnstring&"<BR>节点的文本:("&nodeobj.text&")"
end
returnstring=returnstring&"<BR>{<BR>"
if
returnstring=returnstring&"<BR>属性数有
end
for
returnstring=returnstring&"<li>"&nodeobj.attributes(i).Name&":
next
if
if
set
childnodelen=nodeobj.childNodes.Length
returnstring=returnstring&"<BR><BR>有
for
returnstring=returnstring&"<li>"&childnodeobj.item(i).nodeName&"</li>"
next
end
end
returnstring=returnstring&"<BR>}<BR>"
response.write
set
end
End
可以这样用:
If
Set
xmlDOC.load(xmlhttp.responseXML)
showallnode
Set
Else
Response.Write
Response.Write
End
POST:
url
SoapRequest="username="&username&"&password="&password
Set
xmlhttp.Open
xmlhttp.setRequestHeader
xmlhttp.setRequestHeader
"
xmlhttp.setRequestHeader
xmlhttp.Send(SoapRequest)
Response.Write
Response.Write
Set
'POST
If
Set
xmlDOC.load(xmlhttp.responseXML)
showallnode
Set
Else
Response.Write
Response.Write
End