Reputation: 45
I'm using Blazor 0.9. When ever I try to use http post. My browser(Chrome) gives a proxy error 502. AND ONLY ON POST NEVER GET.
Everything works fine when testing it on localhost. I'm using apache2 reverse proxy.
Also nothing gets logged in the database either.
Don't know what to do, i'm not an experienced web developer, please help.
Response from server
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Proxy Error</title>
</head><body>
<h1>Proxy Error</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
The proxy server could not handle the request <em><a href="/api/FoodHistory/test/1/5/2019">POST /api/FoodHistory/test/1/5/2019</a></em>.<p>
Reason: <strong>Error reading from remote server</strong></p></p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at ******* Port 80</address>
</body></html>
Apache2 config
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/ retry=1 acquire=3000 connectiontimeout=28800 timeout=28800 Keepalive=On
ProxyPassReverse / http://127.0.0.1:5000/
ErrorLog /var/log/apache2/app-error.log
CustomLog /var/log/apache2/app-access.log common
</VirtualHost>
Example of Http Post function (server)
[HttpPost("{user}/{day}/{month}/{year}")]
public IActionResult PostFoodHistory(
[FromRoute]string user,
[FromRoute]int day,
[FromRoute]int month,
[FromRoute]int year,
[FromBody]Shared.PostFoodHistory postFood) {
...}
(client)
@inject HttpClient Http
@functions{
async Task Post() {
await Http.PostJsonAsync(
"/api/FoodHistory/test/1/5/2019",
new PostFoodHistory() {
foodId = food.id,
measurement = 0,
}
);
}
}
Upvotes: 0
Views: 518
Reputation: 45
Finally figured it out!
It was a permission problem by Ubuntu. so I just chmod 777 recursively the whole app directory and everything works now.
But I heard you are not supposed to do that because of security issues?
Anyway, write permission was the problem :)
Upvotes: 2