What i have done so far:
I have added my website .net framework 4.7.1 into IIS, i browsed the website and works on http://localhost which i added all the web files to the wwwroot.
I have a values controller that extends Api controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace NewsFeedWebApi.Controllers
{
public class ValuesController : ApiController
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
// POST api/values
public void Post([FromBody] string value)
{
}
// PUT api/values/5
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
}
And this is my React NAtive Code:
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useState, useEffect } from 'react';
import { Button, View, Text, StyleSheet, TouchableOpacity, } from 'react-native';
function App() {
useEffect(() => {
// Update the document title using the browser API
function GetInit(){
fetch('https://192.168.1.32:80/api/values')
.then((response) => response)
.then((json) => {
console.log(json);
})
.catch((error) => {
//alert(error);
console.log(error);
});
}
GetInit();
});
return (
<View><Text>wwww</Text></View>
);
}
export default App;
In the webconfig i added thisto enable cors:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Credentials" value="true" />
</customHeaders>
</httpProtocol>
Can someone tellme where im making a mistake or something im missing?