Carlos Ancona
Carlos Ancona

Reputation: 67

HttpWebRequest GET ProtocolViolationException WP7

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);

Upvotes: 1

Views: 246

Answers (1)

Soonts
Soonts

Reputation: 21966

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.

Upvotes: 1

Related Questions