Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want send an post request to Api server to update my article views count. I am able to do this via Postman by running http://127.0.0.1:8000/api/updateViews/19 (19 is article id).
I tried http.post() method but could not send request to server.
I just want to send post request whenever anyone open the article detail page.
below is the sample code for flutter post request using http package.
var response = await http.post('http://127.0.0.1:8000/api/updateViews/19',
body:{your post body goes here},
headers : {headers as per your backend needs}
);
after above code you can handle the result of the post request, you can send some success code and error code as response from backend.
for further knowledge visit
Related
I am writing a rest api which will provide some information based on the inputs in the request body. I am a bit confused which http method should I use i.e GET or PUT or POST.
As I know there will be request body so I am ruling out GET from this, as I did some research and found few server implementations may ignore request body for GET.
Now , the question remains should I use POST or PUT.
Considering the output of the API will remain same for same input provided (eg: if input is 1 and output is true, output will always remain true for input 1) which means the method should be idempotent, I am leaning more towards using PUT as compared to POST. Just want to confirm if I am thinking in the right direction.
Would be grateful for any help provided over this.
GET request should not have a request body in HTTP/1.1, more reading:
HTTP GET with request body
PUT as the name suggests puts a resource somewhere, so it's not the request to choose either.
POST is what I would choose to do something like that.
Or you could parse the data into the URL for GET.
(More reading: What's the difference between a POST and a PUT HTTP REQUEST?)
(It's one of my first answers - please leave feedback so I could improve!)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I want to add User Registration and Login into my Angular2-App.
I found this great tutorial from Jason Watmore . I cloned his repo and checked everything according to his tutorial and also tried the suggestions in his comments.
But still, when i want to access the page at all I get the error below. There seem to be more people with the same problem.
My MongoDB is v3.4.1
Do you have any hints for me? Thanks!
UnauthorizedError: No authorization token was found
at middleware (...\server\node_modules\express-jwt\lib\index.js:80:21)
at ...\server\node_modules\express-unless\index.js:47:5
at Layer.handle [as handle_request] (...\server\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (...\server\node_modules\express\lib\router\index.js:317:13)
at ...\server\node_modules\express\lib\router\index.js:284:7
at Function.process_params (...\server\node_modules\express\lib\router\index.js:335:12)
at next (...\server\node_modules\express\lib\router\index.js:275:10)
at jsonParser (...\server\node_modules\body-parser\lib\types\json.js:103:7)
at Layer.handle [as handle_request] (...\server\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (...\server\node_modules\express\lib\router\index.js:317:13)
Console says:
GET http://localhost:3000/ 401 (Unauthorized)
The route is protected from your backend aka your server.js
your server which im assuming is being run on port 3000 is protected unless you provide a token on your indicated method to which your authorizer will extract from usually its the headers.
to over come this i recommend getting a token from aka do a request that will produce one, usually there's a route setup and you can use postman to post data to get a token, once you have a token use postman to send a get request to that same route you couldn't get access to but make sure you add the header authorization or w.e it's looking for the token on. then you'll get access.
I am trying to access a rest-api from Tosca. For now I am using the "Communicate: Rest over HTTP"-module as described in the manual and in the webinar.
The communication has the following sequence:
At the beginning, the client logs in to the server and receives a session-string in the data part of the packet.
The server then expects this session-string as a cookie in each request.
My problem now is to put this new cookie (for example "session=somerandomdata") into the CookieResource.
Unfortunately the manual only applies to already existing CookieRecources.
My question is now whether it is possible to build a CookieRecource with this new cookie.
Whenever a Set-Cookie-Header is returned from the server, a new cookie resource is created.
Please check the manual here: https://support.tricentis.com/community/manuals_detail.do?lang=en&version=10.0.0&url=tbox/wse_tc_session_cookies.htm --> a new cookie resource is created with the name "myCookieResource". This cookie resource can later on be used in the "send" part.
Does this answer your question?
Just wondering what HTTP status code I should return for a REST api if the posted data already exists. Example if I have a create account API that requires an email.
1) If this email already exists on my DB, what status code should I return?
2) If I redirect to another page, like an existing account login page, should the status code then be 200? or 300 for redirection?
If this question has been answered, please just give me the link and I can delete this, but so far I only saw questions for invalid data.
This post suggests to use the 409 Conflict status code when duplicated data is submitted.
This post if a follow-up question to mt previous post:
Android RESTful Web application using Zend Framework
I have written a web application which is based on the Zend Framework (Version 1.11.11) and I want to use the SAME backend code for coding the mobile version of this application (Android). To achieve this, I want to get the response for each of the actions in the controllers in XML and JSON - for mobile-based app.
Using the answers provided in the above link, I am able to get the XML and JSON response by making use of the AjaxContext helper. I set the contexts as json for the required actions in the init method and I am getting the desired json response.
Now I have another challenge. How to know from the URL if the given action was a GET or a POST request? Do I have have to add that as a query parameter? Is that the correct way?
For example, for login action within User controller: URL will be: [link] (http://localhost/user/login)
But within the loginAction, I check if the given request if a post and authenticate only if the request is a post. So the URL: http://localhost/user/login?format=xml will always return to me the response for a GET request since there is no way of knowing if the request was a GET or POST. Please help.
Thanks.
Abhilash
like you added format parameter do the same for request . Use "method" parameter to decide what type of request is it . Or you can also do is
$this->getRequest()->isPost(); //create
$this->getRequest()->isGet(); //read
$this->getRequest()->isPut(); // update
$this->getRequest()->isDelete(); // delete