locked
EndResponse throw System.NotSupportedException RRS feed

  • Question

  • Hi everybody 

    i try to make a web request and i get this error. Below is the code.

    Does anybody have a hint?

     

    1          private void UserControl_Loaded(object sender, RoutedEventArgs e)
    2            {
    3                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("http://serveur-dev/index.html"));
    4                
    5                request.Method = "POST";
    6                // don't miss out this 
    7                request.ContentType = "application/x-www-form-urlencoded";
    8                request.BeginGetRequestStream(new AsyncCallback(RequestReady), request); 
    9                
    10           }
    11           void RequestReady(IAsyncResult asyncResult)
    12           {
    13               HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
    14               Stream stream = request.EndGetRequestStream(asyncResult);
    15   
    16               // Hack for solving multi-threading problem 
    17               // I think this is a bug 
    18               this.Dispatcher.BeginInvoke(delegate()
    19               {
    20                   // Send the post variables 
    21                /*   StreamWriter writer = new StreamWriter(stream);
    22                   writer.Write("WAA_PACKAGE=myfirst&WAA_FORM=SayHello&TheName=Blochaou");
    23                   writer.Flush();
    24                   writer.Close();
    25                 * */
    26                   request.BeginGetResponse(new AsyncCallback(ResponseReady), request);
    27               });
    28           }
    29   
    30   
    31   
    32           void ResponseReady(IAsyncResult asyncResult)
    33           {
    34               HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
    35               if (request == null)
    36               {
    37                   resultBox.Text = "null request";
    38               }
    39               try
    40               {
    41                   HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
    42                   if (response != null)
    43                   {
    44                       this.Dispatcher.BeginInvoke(delegate()
    45                       {
    46   
    47                           Stream responseStream = response.GetResponseStream();
    48                           StreamReader reader = new StreamReader(responseStream);
    49                           // get the result text 
    50                           string result = reader.ReadToEnd();
    51                           resultBox.Text = "toto";
    52   
    53                       });
    54                   }
    55                   else
    56                   {
    57                       this.Dispatcher.BeginInvoke(delegate()
    58                       {
    59                           resultBox.Text = "null";
    60                       });
    61                   }
    62               }
    63               catch (WebException we)
    64               {
    65                   this.Dispatcher.BeginInvoke(delegate(){
    66                       resultBox.Text = we.Message;
    67                   });
    68                   
    69               }
    70   
    71               
    72           }
    
     
    Thursday, April 23, 2009 8:35 AM

Answers

  •  Hi,

    Base on this msdn article: http://msdn.microsoft.com/en-us/library/system.notsupportedexception(VS.95).aspx

    System.NotSupportedException is thrown when an invoked method is not supported, or when there is an attempt to read, seek, or write to a stream that does not support the invoked functionality.

    You can try to check  which code line this exception was thrown at, to find the method that your are using  is not supported,

    Wednesday, April 29, 2009 4:34 AM