Question

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);
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top