The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
HTTPClient for Windows Phone 8.1 gives error “NotFound” on PostAsync Method RRS feed

  • Question

  • I am using HTTP Client in Windows Phone 8.1 to hit EWS and get Inbox. When I run the app it works fine for first time and I am able to get the data.However when I refresh and the same code is executed it give me an Error "NotFound". I am surprised if works once and the it doesn't the next time. I stop the program and re run it works for first time and doesn't the next time onwards.

    Below is my code -

    HttpClientHandler ClientHandler = new HttpClientHandler();

                ClientHandler.AllowAutoRedirect = false;

                ClientHandler.Credentials = UserCredentials;

                ClientHandler.ClientCertificateOptions = ClientCertificateOption.Automatic;

                HttpContent RequestPacket = new StringContent(RequestXML, Encoding.UTF8, "text/xml");

                try

                {

                    using (HttpClient Client = new HttpClient(ClientHandler))

                    {

                       

                        Client.BaseAddress = new Uri(URL);

                        Client.DefaultRequestHeaders.Accept.Clear();

                        using (HttpResponseMessage Response = await Client.PostAsync(Client.BaseAddress, RequestPacket))

                        {

                            Response.EnsureSuccessStatusCode();

                            HTTPErrorString = Response.StatusCode.ToString();

                            ResponseHeaderString = (Response.Headers.Location != null ? Response.Headers.Location.ToString() : "");

                            if (Response.IsSuccessStatusCode)

                            {

                                using (Stream ResponseStream = await Response.Content.ReadAsStreamAsync())

                                {

                                    ResponseEnvelop = XElement.Load(ResponseStream);

                                    return true;

                                }

                            }

                            else

                            {

                                return false;

                            }

                        }

                       

                    }

                }

                catch

                {

                    return false;

                }

                finally

                {

                    ClientHandler.Dispose();

                    RequestPacket.Dispose();

                    ClientHandler = null;

                    RequestPacket = null;

                }

    Thanks,

    Sadiya

    Saturday, April 25, 2015 7:52 PM

All replies

  • Just a guess by maybe you are losing the UserCredentials between the first and second run of the code.  The Not Found might be for the user instead of the url
    Sunday, April 26, 2015 12:49 PM
  • I checked source code of HttpClient PostAsync method, it sends a http Post method request, I guess it's the EWS server restricting successive calls.  Consult EWS support would be necessary.

    Join apps request, talk about startup ideas.

    Sunday, April 26, 2015 3:25 PM