Login/register 308 error
I have a web app + database hosted in python which I have tested and works for creating, logging in and logging out user. Now I'm trying to make the requests in my android application written in java. However, I keep getting 308 error.
Here is my RegisterActivity.java
and this is the most important part of GsonRequest which should parse JSON into string:
Any help is appreciated!
27 Replies
⌛
This post has been reserved for your question.
Hey @Erky! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
@Erky Please attach the error as well.
The website is returning 308 response code, was it configured to do that?
dont think so
# Create user
@app.route('/user/', methods=['POST'])
def create_user():
# Get the data from the database
data = request.get_json()
username = data['username']
password = data['password']
# Handle already existing user
user_already_exists = User.query.filter_by(username=username).first()
if user_already_exists is not None:
return jsonify(response='Error: User already exists'),409
# Generate password hash and add it to a new user
new_user = User(username=username)
new_user.generate_password_hash(password)
# Add the new user to the database
db.session.add(new_user)
db.session.commit()
# Return value
return jsonify(response='Successfully created a new user'), 200
308 is a redirect code..
yeah, maybe i can set it to follow redirects?
Yes
Try that
how
How are you sending request?
Through which library/package?
HttpClient?
HttpRequest?
in python im using flask to send requests i think, and then im using volley to post requests, and then gson library to convert
but not sure, something in volley i think, sorry not 100% sure
Something like this
Implement this in your GsonRequest..
Otherwise..
request.setRetryPolicy(new DefaultRetryPolicy(10000, 1, 1.0f))
Could work
Oh I think I know why this is happening
@Erky Change your url from https://tddd80-app-joneri.azurewebsites.net/user
to https://tddd80-app-joneri.azurewebsites.net/user/
Or from https://tddd80-app-joneri.azurewebsites.net/user/
to https://tddd80-app-joneri.azurewebsites.net/user
(PYTHON)i dont see what changed?
The
/
in the lastE/Volley: [16230] NetworkUtility.shouldRetryException: Unexpected response code 400 for https://tddd80-app-joneri.azurewebsites.net/user/
now got this errorCheck your python app
Did it log anything
Well
It's clear why that happened
unfortunately dont think i can do that, i think my friend is hosting the web app
why's that?
You have data set at headers
Not body..
Use
request.headers
to access them.ohh I see at userObject or? not seeing headers
because its still going into
error -> im going here
response -> not here
userObject
is headersyes , but userObject is a Map with <string> <string> which should take in username and password, but i dont get how i can modify so i get the "headers"
i have the strings
user
pass
which i want to pass as headers into my gsonrequest
You'll need to either post JSON Body data
or accept data form the headers instead of body in python flask
how can i post json body data?
GeeksforGeeks
How to Post Data to API using Volley in Android? - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
is it possible to post the user and pass strings as parameters in my request?
so I should make a StringRequest instead?
tried what you suggested and now got 500 error,
oh wait i think i got it to work! thank you man 🙂
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@272473391041347585>.