I have problem to proceed HTTP request from Browser with Flutter Web Application
ERROR MESSAGE
BACKEND
127.0.0.1:52159 - "POST /signIn HTTP/1.1" 422 Unprocessable Entity
FRONTEND
ClientException: XMLHttpRequest error., uri=http://127.0.0.1:8000/signIn
My Code
Back-End
@app.post("/signIn", response_model=ApiResponse)
def login(auth: AuthModel):
response = au.signIn(auth)
return response
- AuthModel
class AuthModel(BaseModel):
uid: str = None email: str password: str name: str = None
- ApiResponse
class ApiResponse(BaseModel): message: str description: str = None success: bool status_code: int data: dict = {}
Front-End
Future\<bool?\> signIn() async {
try {
final response = await http.post(
Uri.http(\_url, '/signIn',),
body: authData,
headers: {
"Access-Control-Allow-Origin": "\*"
}
);
print(response.body);
SharedPrefs.setToken(json.decode(response.body)\['data'\]\['token'\]);
return true;
} catch (e) {
print(e);
return false;
}
}
Environment INFO
- Flutter (Channel master, 3.12.0-11.0.pre.12, on macOS 13.4.1 22F82 darwin-x64, locale en-DZ)
- Python v3.11
- FastApi v0.100.0