web apiを使用してxamarin.androidのsql azureで新しいユーザーを作成しようとしました。私は私が得た新しいユーザーを作成するときに、私は、私はXamarin.Androidから作業していないユーザーを作成するWebApi
{"$id":"1","message":"No HTTP resource was found that matches the request URI 'http://xamari/nlogin20170612105003.azurewebsites.net/api/Login'.","messageDetail":"No action was found
新しいユーザーを作成しようとするたびにそう、このウェブAPIが認証を行い、新規ユーザーを作成するために提供され、私のログインがエラー罰金ではありません。このエラーメッセージが表示されましたが、そのエラーメッセージ。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using XamarinLogin.Models;
namespace XamarinLogin.Controllers
[RoutePrefix("api/Login")]
{
public class LoginController: ApiController
{
xamarinloginEntities db = new xamarinloginEntities();
/
[HttpPost]
[ActionName("XAMARIN_REG")]
// POST: api/Login
public HttpResponseMessage Xamarin_reg(string username, string password)
{
Login login = new Login();
login.Username = username;
login.Password = password;
db.Logins.Add(login);
db.SaveChanges();
return Request.CreateResponse(HttpStatusCode.Accepted, "Successfully Created");
}
[HttpGet]
[ActionName("XAMARIN_Login")]
// GET: api/Login/5
public HttpResponseMessage Xamarin_login(string username, string password)
{
var user = db.Logins.Where(x => x.Username == username && 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");
}
}
}
}
、これは私のxamarin.androidでユーザースクリプトを作成します:ここで
は私のWeb APIコントローラーがあるので、私のせいではここで何
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace LoginAzureDroid
{
public class NewUserActivity : Activity
{
EditText txtusername;
EditText txtPassword;
Button btncreate;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.Reg);
txtusername = FindViewById<EditText>(Resource.Id.txtsaveusername);
txtPassword = FindViewById<EditText>(Resource.Id.txtsavepassword);
btncreate = FindViewById<Button>(Resource.Id.btnsavecreate);
btncreate.Click += Btncreate_Click;
}
private async void Btncreate_Click(object sender, EventArgs e)
{
Login log = new Login();
log.username = txtusername.Text;
log.password = txtPassword.Text;
HttpClient client = new HttpClient();
string url = "http://xamarinlogin20170612105003.azurewebsites.net/api/Login";
var uri = new Uri(url);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response;
var json = JsonConvert.SerializeObject(log);
var content = new StringContent(json, Encoding.UTF8, "application/json");
response = await client.PostAsync(uri, content);
if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
{
var errorMessage1 = response.Content.ReadAsStringAsync().Result.Replace("\\", "").Trim(new char[1]
{
'"'
});
Toast.MakeText(this, errorMessage1, ToastLength.Long).Show();
}
else
{
var errorMessage1 = response.Content.ReadAsStringAsync().Result.Replace("\\", "").Trim(new char[1]
{
'"'
});
Toast.MakeText(this, errorMessage1, ToastLength.Long).Show();
}
}
}
}
を、それは私のURLですか? Web APIのコードですか?またはxamarin.androidの私のコード。
ヘルプ誰ください –
それはあなたのURLかもしれませ 'ます。http:// xamari/nlogin20170612105003.azurewebsites.net/API/Login'私は誰かがxamarinを分割想像することはできませんinto(xamari/n) –