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.
Related
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
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/
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Java: Simple SOAP Client
How to create java client using WSDL? and how to run or test that client?
Firstly, you have to genrated client stubs from the wsdl.
1. You can use Eclipse to generate client stubs
2. Or using WSDL2JAVA class of the axis.jar
3. Then, configure the PortType of the proxy and invoke appropriate operation
ex:
serviceProxy.setEndpoint(endPoint);
Service_PortType service_PortType = serviceProxy.getService_PortType();
((Stub) service_PortType )._setProperty(Call.USERNAME_PROPERTY,"username");
((Stub) service_PortType )._setProperty(Call.PASSWORD_PROPERTY,"password");
serviceProxy.setService_PortType(service_PortType );
Response response = serviceProxy.operation(Request);
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.
This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
How to send HTTP request in java?
How to use java.net.URLConnection to fire and handle HTTP requests?
using java, how do i hit any url?
for instance, opening of http://www.xyz.com/node1 in a browser will tell xyz.com that node1 is hit.
so in this java program (which sends sms text say 'node1' in example above embedded in the url itself to a sms gateway server)
how do i achieve it without opening any browser or using servlet.
You can use an HttpURLConnection.
But using it directly is overkill if you just want to load the URL in question. This guide shows you how to open a URL.
Basically it boils down to:
URL url = new URL("http://www.xyz.com/node1");
URLConnection conn = url.openConnection();
conn.connect();
//...
The simplest way is to use URL http://download.oracle.com/javase/1.4.2/docs/api/java/net/URL.html. For more advanced/flexible URL fetching you could use HttpClient http://hc.apache.org/httpclient-3.x/