Используя ax ios с reactjs для вызова asp. net api localhost - PullRequest
1 голос
/ 04 февраля 2020

Я провел много часов. Я решил опубликовать вопрос.

У меня есть API, разработанный asp. net для решения.

public class ApiOpsController : ApiController
    {
        private static readonly IOpsRepository OpsRepository = new OpsRepository();

        public IEnumerable<Opdt> Get(string styleCode, string styleSize, string styleColor, string revNo, string opRevNo,
            string edition, string languageId)
        {
            return OpsRepository.Get(styleCode, styleSize, styleColor, revNo, opRevNo, edition, languageId);
        }
    }

Я запускаю решение, затем использую почтальон для проверки API

http://localhost: 63762 / api / ApiOps? styleCode = UAR0348 & styleSize = RGL & styleColor = 001 & revNo = 002 & opRevNo = 001 & edition = MES & languageId = en

*1011*enter image description here

Конечно, это также работает.

Я вызываю API для моего Reactjs проекта

  const config = {
    method: "get",
    url: "http://localhost:63762/api/ApiOps?styleCode=UAR0348&styleSize=RGL&styleColor=001&revNo=002&opRevNo=001&edition=MES&languageId=en",   
    headers: {
      "Content-Type": "application/json; charset=utf-8"
    }
  };

  let res = await axios(config).catch(error => console.log(error));;

Это выдает мне эту ошибку

enter image description here

Заметил: я пытался положить: "proxy": "http://localhost:63762" для упаковки. json, все еще не работает.

...