I need to make a GET request with headers (this is the requeriment) but i am receiving the Protocol Violation Exception.

This is my code:

      System.Uri targetUri = new System.Uri("http://54.219.33.208:8080/wsrewards/consultaEstatusRewards");
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri);
        request.Method = "GET";
        request.Headers["idUser"] = user;
        request.Headers["auth"] = autho;
        request.BeginGetRequestStream(new AsyncCallback(ReadWebRequestStreamCallbackConsultaEstatusRewards), request);
有帮助吗?

解决方案

MSDN on BeginGetRequestStream says: Begins an asynchronous request for a Stream object to use to write data.

With GET method, you can't write any data to request. BeginGetRequestStream is only for e.g. POST and PUT methods.

You should probably replace your BeginGetRequestStream with BeginGetResponse, and then call HttpWebResponse.GetResponseStream() method of the response object to access the response stream.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top