0

I am new to iOS. I searched similar questions but couldn't find right answer for my situation.

I created asp.net web api (slected only web api option not selected MVC option) But I made model Account and controller AccountsController which is an ApiContoller

in my AccountsController:

[Authorize]
// GET: api/Accounts
    public IQueryable<Account> GetAccounts()
    {
        return db.Accounts;
    }

    // GET: api/Accounts/5
    [ResponseType(typeof(Account))]
    [Route("api/account/{id}")]
    public IHttpActionResult GetAccount(int id)
    {
        Account account = db.Accounts.Find(id);
        if (account == null)
        {
            return NotFound();
        }

        return Ok(account);
    }

And my Account model:

public class Account
{
    public int Id { get; set; }
    public string UserName { get; set; }
    public string UserEmail { get; set; }
    public decimal Rebate { get; set; }
    public decimal MemCom { get; set; }
}

When I run http://tresmorewebapi.azurewebsites.net/api/accounts

I get all lists of accounts.

How can I create simple ios app in swift that shows lists of Account table? And after I inserted [Authorize] to AccountsController, I get error message Authorization has been denied for this request by same http GET request http://tresmorewebapi.azurewebsites.net/api/accounts

How can I send http request with authorization..?

I guess anyone who read this question can POST to my server..??

If someone can lead me to this step.. I think I can get further..

Thank you very much!

Steve Kim
  • 21
  • 8
  • So, it is hard to answer this question without seeing your code. But basically you should integrate your authorization method (based on which one you are using) to http headers. I think the easiest way is to use some library for this network operations. You may want to check Alamofire for this. https://github.com/Alamofire/Alamofire#authentication – Güngör Basa Apr 18 '17 at 20:49
  • Actually, please look at this post. Everything is working properly http://stackoverflow.com/questions/38292793/http-requests-in-swift-3 – Güngör Basa Apr 18 '17 at 20:58

0 Answers0