WS POST generates 405 error, but works in Postman - web-services

Running locally against Tomcat 9, my GET endpoints are working fine, but any POST attempt generates a 405 error. So I tried to simplify the request down to the following to eliminate the possibility of downstream code/processing somehow generating the 405 problem
#POST
#Path("/form")
public Response addUser(
#FormParam("name") String name,
#FormParam("age") int age) {
return Response.status(200)
.entity("addUser is called, name : " + name + ", age : " + age)
.build();
}
The corresponding URL I am trying:
http://localhost:8080/rest/committee/form?name=joe&age=27
Works as expected in both Postman and the Intellij WS/Rest testing tool. However, whenever I run it directly in the browser I get a 405 error. As is the case so often with me, I think I'm missing something really fundamental. Any suggestions appreciated!

If you try that URL in your webbrowser directly it will per default use GET not POST. As a result the server will reject the call.
if you want you browser to send a post call, you'll have to create a html form that posts the data to the service.

Related

Django rest-auth PUT method returning JSON Unexpected token

I've been trying to try to do this for a couple of days for now. I am trying to update the user's data through put method in Django using rest framework. However, I've been receiving this error message in the console.
This is the fetch function that is used to send the data to the backend. As it's shown, I'm even trying to compare it to other fetch methods and I think nothing is wrong with the body of the fetch.
Below are my codes used to update the data.
views.py
serializers.py
urls.py
So, the error is
Unexpected token < in JSON
which means that it tried to parse a response containing a character <. If I had to guess, the response is a HTML document, because it would start with < (<html>...).
For instance, it can be a 404 error page because the URL was not found. The best way to know is, instead of logging response.json(), just log response.text(). Until you do that, hard to know what really happens.

Postman inconsistent behaviour with cURL request

I have the following API downloaded in JSON from Swagger Editor:
PUT http://10.37.64.243/m2m/fim/items/fim:device:manager/operations/getAllDeviceTypes?exclude={{exclude}}
with exclude being an environment variable set as : href,metadata,name,arguments
Nominal use requires basic authentication, in this case it works and I get a JSON body with expected result. It properly works in Postman (so I think my import is correct)
If no authentication is provided:
in Swagger Editor : nominal behaviour, request is rejected with error code 401
in Postman : UNEXPECTED behaviour, I end up with status code 200 and it returns a response body identical to the one that I get when authenticated
if I generate the cURL code snippet from Postman and launch it out of Postman: nominal behaviour, I get the same error as the one I get in Swagger Editor (the one expected)
Why do Postman behave differently from the cURL request ??
I probably do something wrong, but I can't figure out what
Thanks for any help
Alexandre
I finally found out that the server returns a cookie that holds authentication validation. So after a valid authentication, whatever the request (with or without authentication) it will be considered as authentified.
Unfortunately, the only way to overcome that problem is to remove the cookie by hand through the "Manage cookies" window. Postman does not implement a function that erase it (even through the pm.cookies and pm.cookies.clear() function).
Postman developpers are aware of that, but there's no scheduling for this feature ...
EDIT: the feature is followed here https://github.com/postmanlabs/postman-app-support/issues/3312

REST API call works in ARC client but not in postman or code

I have a REST API, which works fine in Advanced REST Client(ARC) but not working in postman and through code.
Weird part is postman throwing 405 error and when accessed through code it throws 400 error code.
The rest api is pinterest pin api : https://api.pinterest.com/v1/pins?access_token="token"
Header for request - Content-Type : application/json
I don't think its an issue with Pinterest, because it works fine with ARC client.
Any idea on this issue?
Remove the header and it should work. Not sure why that header creates a problem but once I removed that header it worked for me.
STEPS:
I went on Pinterest API-Explorer
There I've selected Pins -> Return information about a Pin
Then I've generated new token and used one Pin ID.
Tool generates url that looks like
https://api.pinterest.com/v1/pins/368661919478924883/?access_token=ACCESS_TOKEN&fields=id
I've used this same URL in Postman, Get Operation and no headers.
Result I get is:
{
"data": {
"id": "368661919478924883"
}
}

Facebook returning HTTP status code 502 while making a GET Request

I am trying a GET request from Facebook for a batch of ids using my app access token separated by a comma.
Please find below the call:
https://graph.facebook.com/?ids=1374186930,100005305471358,1516423103,100003031846875,100002939786624,100004705179654,522691095,100002893804783,100005269178084,1417831236,100004652521769,100003511989378,100002394692546,1646211152,1092931510,100000152985362,100004151552444,100004122698187,100001574061632,100005007584068&access_token=<my_app_access_token>&format=json
Facebook returns an error intermittently for some of these requests with an HTTP status code of 502.
I've tried fetching for these ids using the graph API explorer as well as the app access token later. They have been fetched properly. I have performed some research, but all issues of Facebook were related to open graph and 502 is "Bad Gateway Error". Since mine is not a web app, I cannot even refresh a browser to make the call again. This is a normal call made to Facebook API.
The error returned by Facebook is html which contains the following message:
"Sorry, something went wrong. We're working on getting this fixed as soon as we can."
Since they have given this response, I want to know if someone is facing this issue as well and if somebody could tell me, when this will be resolved.
This is affecting the other calls as well and there is a delay in the fetching.
Thanks in advance.
The Error 502 means that the message is too large. I do not know exactly the maximum size. Curiosity. What language are you using??
Good Bye

Problem with Posting JSON object with WSRequest

I want Play to call a webservice. The webservice accepts application/json and returns this as well. With the following code I'm trying to achieve this. (Note, the headers.put(xxx) are added later in an effort to solve the problem).
WSRequest request = WS.url(targetURL);
request.body = new Gson().toJson(user);
request.headers.put("Content-type","application/json");
request.headers.put("Accept","application/json");
request.post();
The strange thing is that my JBOSS server replies: "Cannot consume content type". If I use my 'Simple REST client' plugin in my Chrome browser, and provide the entire JSON Body GSon created and add the content-type header, I get a valid response. Is this not the way to send JSON to the server? Or am I missing some fundamental piece here?
While checking the API documentation on the WSRequest class i noticed the field mime-type
By setting it as follows JBOSS (resteasy) accepted my request succesfully.
request.mimeType = "application/json";