Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

The requested resource does not support http method 'GET'

$
0
0

i am using Xamarin form,

Post is working using my Xamarin app to Sql server database using Asp.net Api,

but Get is not working to try to log in method.

my code is below.

using Seagullapi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.UI.WebControls;

namespace Seagullapi.Controllers
{
public class LoginController : ApiController
{
LoginEntities db = new LoginEntities();

    // GET: api/Login
    [HttpPost]
    [ActionName("XAMARIN_REG")]
    public HttpResponseMessage Xamarin_reg(login log)
    {
        try
        {
            login llogin = new login();
            llogin.phone = log.phone;
            llogin.password = log.password;
            llogin.email = log.email;
            llogin.first_name = log.first_name;
            llogin.last_name = log.last_name;
            llogin.dateofbirth = log.dateofbirth;
            llogin.address = log.address;
            llogin.city = log.city;
            llogin.state = log.state;
            llogin.zip = log.zip;
            llogin.passwordconfirm = log.passwordconfirm;

            db.logins.Add(llogin);
            db.SaveChanges();
            return Request.CreateResponse(HttpStatusCode.Accepted, "Successfully Created");
        }
        catch (Exception ex)
        {
            return Request.CreateResponse(HttpStatusCode.ExpectationFailed, ex.ToString());
        }

    }


    [HttpGet]
    [ActionName("XAMARIN_Login")]
    // GET: api/Login/5
    public HttpResponseMessage Xamarin_Login(string phone, string password)
    {
        var user = db.logins.Where(x => x.phone == phone && x.password == password).FirstOrDefault();
        if (user == null)
        {
            return Request.CreateResponse(HttpStatusCode.Unauthorized, "Please Enter valid UserName and Password");
        }
        else
        {
            return Request.CreateResponse(HttpStatusCode.Accepted, "Success");
        }
    }
}

}

My log in entities

public partial class login
{
    public string phone { get; set; }
    public string password { get; set; }
    public string email { get; set; }
    public string first_name { get; set; }
    public string last_name { get; set; }
    public string dateofbirth { get; set; }
    public string address { get; set; }
    public string city { get; set; }
    public string state { get; set; }
    public string zip { get; set; }
    public string passwordconfirm { get; set; }
    public string email2 { get; set; }
}

}

please tell me the reason why i cannot work with Get method.

Thank you.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>