Getting 400 bad Request with Tomcat 8.5.9 [duplicate] - java

This question already has answers here:
How to pass a JSON array as a parameter in URL
(9 answers)
Closed 5 years ago.
I'm new to tomcat server technology. Currently I'm working on the spring boot application and I tried calling the below api with the tomcat servers (below 8.5v) running in the background, I got the response as I expected. But when I tried to call the same api with tomcat server 8.5.9v running in the background I'm getting the 400 bad request.
http://localhost:8080/TestRest/ExtractTest?jsonString={"extract":
{"Type":"veswanth", "objects":[{"object":"WTT"}]}}
And in the log file I found the below issue
service Error parsing HTTP request header Note: further occurrences of
HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in the
request target. The valid characters are defined in RFC 7230 and RFC
3986
Kindly help me to fix this issue and correct me if did anything wrong..

You can not pass json data in url in that way. You need to pass it in body and request method should be POST.
You can refer this:
How to pass a JSON array as a parameter in URL

Related

HTTP Status 404 - on Eclipse with Tomcat (with no generated web.xml) [duplicate]

This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 3 years ago.
I'm working on an example with Eclipse and Tomcat 9.0, dynamic web module 4.0, without generating web.xml deployment.
The project directory is as follow:
where reverse.java is a servlet that get the input parameter send it back to the output page.
For some reason, after I hit the submit button, the "/reverse" servlet cannot be reached and tomcat prompts HTTP Status 404 - Not Found page. What did I do wrong?
After hitting the submit button on inputForm.jsp page, it got the error:
Type Status Report
Message /reverse
Description The origin server did not find a current representation
for the target resource or is not willing to disclose that one exists.
URL I called on submit when enter input = "abcd": http://localhost:8080/reverse?input=abcd
What did I do wrong? Thanks.
If you didn't set set context root explicitly, it is set by default to the same name as your project. If your project name is "bla", then the URL to call the servlet should be following: http://localhost:8080/bla/reverse.

Failed to get data when accessing the rest-api method getAll [duplicate]

This question already has answers here:
No 'Access-Control-Allow-Origin' header is present on the requested resource- AngularJS
(12 answers)
Closed 5 years ago.
I'm developing an application which has UI from Angular2 and back-end as a rest api which is done on Spring-boot.
When I access the URL to get the list of users, it doesn't fetch all the users. When I check the browser console I get the following error:
Failed to load http://localhost:8080/api/user/getAll: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Any input will be appreciated.
If the frontend (Angular2) and backend (Boot) live on two different domains a solution would be to enable cors on the backend. Read here: https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/cors.html and here https://spring.io/guides/gs/rest-service-cors/

simulate curl -d request in HTTP [duplicate]

This question already has answers here:
Sending HTTP POST Request In Java
(12 answers)
Convert Curl to Java equivalent
(1 answer)
Closed 5 years ago.
I want to simulate a request of the form curl -d "param = value" "http://ip:port?key1=value1&key2=value2" using the REST API Testing, but unfortunately I do not know how. More details about the -d flag can be found here.
If I use POST for the method type then I get a 405 error and if I use GET for the method type then I get a 404 error. From the command line the command works perfectly and I am able to receive the answer, but I do not know how to adjust the snippet -d "param = value" in a HTTP request.
I really appreciate any kind of help !!!

how to detect whether request is coming from browser or smartphone? [duplicate]

This question already has answers here:
Detecting Device Type in a web application
(8 answers)
Closed 9 years ago.
I am having a web application , which works fine .
now there is a particular page which gets bulky when i access the application from smartphone browser , so I wanted a situation like
if(request comes from computer browser client )
forward to bulky page in web application
else
if (request comes from smartphone )
forward to some other light page .
please put your suggestion how can i achieve this
Use the user-agent. Every connection to your server carries this header, by convenience and convention. There is no guarantee that a browser will be truthful(such as a spambot reporting itself as Chrome). You can get the user-agent as follows:
request.getHeader("User-Agent");
and then check again known user-agent strings and templates.
It's generally done by checking "User-Agent" header of Request

how to send HTTP request to a servlet [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to send HTTP request in java?
I only have one servlet running on the Tomcat server side. Now I want to send a HTTP request to this servlet from a Swing application, and it's not an APPLET application (because I see some examples sending request from applet). How can I do this?
While you can open a direct socket connection and send the raw HTTP headers & content and receive a response back, I would urge you to take a look at HttpRequestBase.

Categories