Sto ottenendo il "System.Net.ProtocolViolationExceptionSystem.Net.ProtocolViolationException: è necessario scrivere ContentLength byte al flusso di richiesta prima di chiamare [Iniziare] GetResponse
: È necessario scrivere ContentLength byte al flusso di richiesta prima di chiamare [Begin] GetResponse "errore durante la chiamata al metodo" BeginGetResponse "della richiesta web.
Questo è il mio codice:
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();
}
In particolare, dopo aver chiamato alla funzione "getRequestStream()", il flusso sta gettando questa eccezione per la lunghezza:
'flusso .Length 'ha gettato un'eccezione di tipo' System.NotSupportedException '
Che cosa potrebbe causare?
Si prega di non aggiungere "alot cercato" e "grazie" al tuo post. Per mostrare lo sforzo - inserisci il codice (ok come è nel post corrente) e link alle soluzioni che hai provato con una frase breve che non ha risolto il tuo problema. –
possibile duplicato di [System.Net.ProtocolViolationException Eccezione C# Post e Getresponse] (http://stackoverflow.com/questions/18192423/system-net-protocolviolationexception-exception-c-sharp-post-and-getresponse) –
Quella domanda spiega un errore diverso da questo, quindi non è duplicato. – user3815821