I'm trying to return data from our TeamCity server to my React web app using an axios get request. Unfortunately I am not able to enable CORS on the server and always end up with a 401: Unauthorized, or with 'Response for preflight is invalid (redirect)' error.
I have tried to pass the username and password in the headers:
componentDidMount() {
var config = {
"headers": {
"username": "username",
"password": "password"
}
}
// Make axios http request to TeamCity server with authentication headers
axios.get('http://teamcity/app/rest', config)
.then(res => res.json())
.then(res => {
// Transform the raw data by extracting the nested posts
const projects = res.data.projects;
// Update state to trigger a re-render.
// Clear any errors, and turn off the loading indicator.
this.setState({
projects,
loading: false,
error: null
});
})
.catch(err => {
// Something went wrong. Save the error in state and re-render.
this.setState({
loading: false,
error: err
});
});
}
I have tried passing the username and password in the url as per this post: How to pass username and password in TeamCity REST API
http://user:pass@server/app/rest/
I have also tried passing the Basic authentication headers from working postman requests.
The request always returns 'XMLHttpRequest cannot load http://teamcity/app/rest. Response for preflight is invalid (redirect)'
I am on the same network as the TeamCity server. Is this possible without enabling CORS?