0

I am making a Windows Phone 8 application where I need to send login credentials to web server(I am using RESTSHARP) and post authentication (response) , I have to do variety of tasks. I was using the following code base but I am getting Not Acceptable error message.

var client = new RestClient("http://com.example");

                var request = new RestRequest("/REsource/", Method.POST);

               // Json to post 


                request.AddParameter("username", userName.Text);
                request.AddParameter("password", Password.Text);
                request.AddHeader("Content-Type", "application/x-www-form-urlencoded");

                client.ExecuteAsync(request, response =>
                {

                    MessageBox.Show(response.StatusCode.ToString());
                                if (response != null && ((response.StatusCode == HttpStatusCode.OK) && 
                                 (response.ResponseStatus == ResponseStatus.Completed))) // It's probably not necessary to test both
                                   {

                                   }
                               else if (response != null)
                                 {
                                MessageBox.Show(string.Format
                        ("Status code is {0} ({1}); response status is {2}",
                               response.StatusCode, response.StatusDescription, response.ResponseStatus));
                    }  
                });

I tried HTTPResponseMessage part of HTTPCLient also and but dont know how to send a POST .

Apoorv
  • 2,023
  • 1
  • 19
  • 42
  • Hi Apporv, Here is a good link to refer for simple POST in WP. http://stackoverflow.com/a/14698947/2549049 – vasuy19 May 16 '15 at 12:11
  • @Apoorv , try this also [.NET HttpClient. How to POST string value](http://stackoverflow.com/questions/15176538/net-httpclient-how-to-post-string-value) – Eldho May 17 '15 at 05:12
  • ACtually I am looking on the RESTSHARP Library for doing this !! The above methods hold fine – Apoorv May 17 '15 at 07:20
  • Does `request.Authenticator = new HttpBasicAuthenticator(userName.Text, Password.Text);` help? – Peter Schneider May 18 '15 at 19:02

0 Answers0