문제

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