simulate curl -d request in HTTP [duplicate] - java

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 !!!

Related

Getting 400 bad Request with Tomcat 8.5.9 [duplicate]

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

Retrive base64-file from multipart/form-data POST request [duplicate]

This question already has answers here:
How can I upload files to a server using JSP/Servlet?
(14 answers)
Closed 6 years ago.
I receive a request (multipart/form-data POST), parameter "file" contains file as a base64 (example below)
------WebKitFormBoundaryEA37wQGzpnprPt8x\r\nContent-Disposition: form-data;
name=\"file\"\r\n\r\nJVBERi0xLjQNJeLjz9MNCjEgMCBvYmoNPDwvQXV0aG9yIChNYXJrbyBLZWpcMjM2YXIpL0Ny\r\nZWF0aW9uRGF0ZSAoRDoyMDE2MTEyMjExMzc0NCswMScwMCcpL0NyZWF0b3IgKE1TIFdvcmQg\r\nRG9jdW1lbnQ
I am curious how to decode it (using JAVA of course) from there and get a file.
Should I somehow delete system information (WebKitFormBoundary and Content-Disposition)?
I also noticed that content full of \r\n Do I need to delete it myself as well?
you can use following link to decode from base64
https://www.base64decode.org/

View http request when using mvn jetty:run [duplicate]

This question already has answers here:
Enable debug logging in maven jetty 7 plugin
(5 answers)
Closed 7 years ago.
Now, I run the simple example of Motown (Link Single application setup)
First, I check out code and install jar. After that, I run "mvn jetty:run". The application starts OK.
I want to review http request sending from browser into application but the console does not have this information. How can I view the http request?
Thanks
One option is to use tcpmon - it is very simple tool, you just change port in the browser sending requests to tcpmon and tcpmon will send the requests to your application but also will print it. The same with responses. (https://code.google.com/p/tcpmon/)

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.

How to do a POST inside a JSP or Servlet? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to use java.net.URLConnection to fire and handle HTTP requests?
I need to do a http post call to an external URL from my servlet. And I need to add some custom http headers too to the message. Is this possible ? please provide me a guidance.
You can try apache HttpClient library.

Categories