0

As the title says I am trying to run a Windows Phone App which is supposed to communicate with a Restful API(running on localhost). My server is actually getting my Http requests but Visual Studio keeps throwing this error: "The remote server returned an error: NotFound."

    private void connect_tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.BeginGetResponse(GetResponseCallback, request);
    }

    void GetResponseCallback(IAsyncResult result)
    {
        HttpWebRequest request = result.AsyncState as HttpWebRequest;
        if (request != null)
        {

                WebResponse response = request.EndGetResponse(result);
                Stream streamResponse = response.GetResponseStream();

                StreamReader streamRead = new StreamReader(streamResponse);
                string read = streamRead.ReadToEnd();

                Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(read);
                    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                });    

                streamResponse.Close();
                streamRead.Close();
                response.Close();
        }
    }

This is the full error:

{System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound. at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.b__d(Object sendState) at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.b__0(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at IonisSphere.Connect.GetResponseCallback(IAsyncResult result) at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClass1d.b__1b(Object state2)}

The Web Exception occurs at the EndGetResponse() call. I removed the try/catch around to see the error but when it's there it always goes in the catch section and nothing happens. I don't understand what is it not finding since my server gets my requests ... It works fine with Postman by the way. I also tried with a POST method but got exactly the same result.

I'm stuck with this since a few days and I couldn't find anyhing helpful on the internet. I am quite new on Windows Phone and I know this is propably a stupid mistake but thanks in advance for the ones who will try to teach me =)

4

0 回答 0