我得到了
"System.Net.ProtocolViolationException:在调用Web请求的"BeginGetResponse"方法时,必须在调用[Begin] GetResponse"错误之前将ContentLength字节写入请求流.
这是我的代码:
try
{
Stream dataStream = null;
WebRequest Webrequest;
Webrequest = WebRequest.Create(this.EndPointAddress);
Webrequest.Credentials = new NetworkCredential(this.username, this.password);
Webrequest.ContentType = "text/xml";
Webrequest.Method = WebRequestMethods.Http.Post;
byteArray = System.Text.Encoding.UTF8.GetBytes(xmlRequest.Children[0].InnerXML);
Webrequest.ContentLength = byteArray.Length;
dataStream = Webrequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
RequestState rs = new RequestState();
rs.Request = Webrequest;
IAsyncResult r = (IAsyncResult)Webrequest.BeginGetResponse(new AsyncCallback(RespCallback), rs);
}
catch (Exception exc)
{
TRACE.EXCEPTION(exc);
}
finally
{
dataStream.Close();
}
Run Code Online (Sandbox Code Playgroud)
更具体地说,在调用函数"getRequestStream()"之后,Stream正在为长度抛出此异常:
'stream.Length'抛出了'System.NotSupportedException'类型的异常
可能是什么原因造成的?
我试图使用vbs脚本发送邮件,但它不起作用.我正在使用服务器smtp.gmail.com和端口587.我们的问题是,当我将端口更改为25时,这是有效的.以下是我使用的代码:
SMTPMail "to", "cc", "TEST", "TEST"
Function SMTPMail(ByVal sTo, ByVal sCc, ByVal sSubject, ByVal sBody)
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
Dim objMessage
set objMessage = CreateObject("CDO.Message")
objMessage.Subject = sSubject
objMessage.Sender = "sender"
objMessage.From = "from"
objMessage.To = sTo
objMessage.CC …Run Code Online (Sandbox Code Playgroud)