Удаленный сервер возвратил ошибку: (501) Не реализовано - PullRequest
0 голосов
/ 05 марта 2019

Я пытаюсь вызвать веб-API из проекта Windows CE, используя vs 2008, это моя реализация:

   private void loginbtn_Click(object sender, EventArgs e)
                {
                    username = usernametb.Text;
                    password = passwordtb.Text;
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/WebSite1/CheckCredentials");

                    request.ContentType = "application/json";

                    // Set the Method property to 'POST' to post data to the URI.
                    request.Method = "POST";
                    request.SendChunked = true;
                    // start the asynchronous operation
                    request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);

                    // Keep the main thread from continuing while the asynchronous
                    // operation completes. A real world application
                    // could do something useful such as updating its user interface. 
                    allDone.WaitOne();
                }
      private static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
            {
                HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

                // End the operation
                Stream postStream = request.EndGetRequestStream(asynchronousResult);
                var model = new login
           {
               username = "U0001",
               password = "1212"
           };
                var json = JsonConvert.SerializeObject(model);
                Console.WriteLine("Please enter the input data to be posted:");
                string postData = json;
                // Convert the string into a byte array.
                byte[] byteArray = System.Text.Encoding.GetEncoding(1252).GetBytes(postData);

                // Write to the request stream.
                postStream.Write(byteArray, 0, byteArray.Length);
                postStream.Close();

                // Start the asynchronous operation to get the response
                request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
            }

            private static void GetResponseCallback(IAsyncResult asynchronousResult)
            {
                HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

                // End the operation
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
                Stream streamResponse = response.GetResponseStream();
                StreamReader streamRead = new StreamReader(streamResponse);
                string responseString = streamRead.ReadToEnd();
                Console.WriteLine(responseString);
                // Close the stream object
                streamResponse.Close();
                streamRead.Close();

                // Release the HttpWebResponse
                response.Close();
                allDone.Set();
            }

Я получаю эту ошибку: «Удаленный сервер возвратил ошибку: (501) Не реализовано. "on line: удаленный сервер возвратил ошибку: (501) не реализовано.

...