I want to send a xml file through POST request to a HTTPS server.
I think i have to read the content of the XML file and save it to a String, then send POST it to the server.
Sorry, but i don't have any code to demonstrate my workings. Can someone help me to do a Sample code or tutorial to start with this task ?
Note : I am using Java
Using java, You can open this XML file in READ mode and start reading and printing contents in browser.
Related
I do not have much experience with JSP/Servlets and I have searched for an answer regarding my problem but have not found an answer to my question.
Lets say I have a file on the back-end, called test.txt, and i want my servlet to stream the file contents to a jsp page dynamically. By dynamically i mean that if the file is being updated, text is being appended to the end of file, then i want the client looking at the resulting html/jsp file to see the changes live.
For example, the client would be able to see the changes in a textbox element in the html document.
Is this possible with JSP/Servlets or not? If so, how would i go about it?
Thanks for your time.
Already tried searching for related questions, searching for stream inquires
and haven't found any answer that would answer my question.
I think that you should probably load the file:
See an example: How should I load files into my Java application?
and reload the page using javascript
See: How to reload a page using JavaScript
I am sure you are not professional in web development , so lets fix it.
When a client (Mobile App , Browser , ... ) wants to send a request to a server , it will create a TCP/IP (we have more protocols like UDP but web applications work on top of TCP/IP protocol) connection. All data between client and server will transfer by this connection. It's your only way to send and receive data from server or client.
When you create a JSP file (and it will compile to Class file when deploy on server application [ for better understand search JASPER JSP ENGINE ] ) to response to requests i will produce a response like this for browser :
some Http-Headers
Content-Type : text/html
some other Http-Headers
{JSP as a html text}
so browser will parse the response , render it and show it to your client user.
It means this jsp page will sent as a static html page.
For update it you have 2 ways :
1- The wrong way : Keep-Alive connection between client and server and each time you want to update client , send whole response to it again ! So all data come and html will render again and ... . So its bad way and not safe and many things else.
2- The correct way : Create a new async connection between client and server using JavaScript and just request for watch data change in file and show it to user in real time , without render whole html page. If this connection use Http protocol (http protocol just is a text protocol not a network protocol like TCP/IP) add Connection : Keep-Alive in your request header to server keep it alive.
Note : if you want understand better , search for socket in java and learn how it works.
I'm working on a play framework 2 application and I would like to call a WebService and send a file ( an image ). I found the WS class but I cannot find how to send a file using it.
What I found is this :
WS.url("http://localhost:9001/post").post("content")
But I did not managed to send a file using a POST request.
Can someone tell me how to do it ?
Thanks.
C.C.
With Play > 2.0 this should do the trick:
File file = new File("yourPath");
WS.url("/post/url").post(file);
Being able to add a parameter identifying your file the request should be send using multipart/form-data.
This Post shows how to do it with Play! - https://stackoverflow.com/a/18723326/2788883
use following method to return response as file
RenderBinary(java.io.File file, java.lang.String name)
To see API follow this link.
I have a Java project upload functionality which is uploading image onto the server location C:/temp and I want same image to show on UI as soon as uploaded but the problem is when i am passing image path(C:/temp) into JSON then then system is reading that image path relative to project and getting an error
(NetworkError: 404 Not Found - http:// localhost:8080/group/images/c:/temp/Jellyfish.jpg")
because file is present in C:/temp. What would be the possible solution of this. please help me guys?
Thanks,
Ankit
You need a servlet that will read the file from c:\temp, and send the read bytes to the servlet's response output stream. You will also need to set the content type of the response to the mime type of image you're sending (image/png for example), and the content length to the number of bytes in the file.
And this is the URL of this servlet that you will have to pass into the JSON object.
I have read plenty of explanations about how to upload files to a server through XML using C#, but I have not found how to do the same using Java and have not been able to figure it out at all. I wonder if anybody on you have done this job successfully.
My intention is to do an HTTP posts containing some text values as a caption and description of an image file, then post them and the image file to the web server through XML.
It's very easy to use Jersey to upload files. Actually, it will enable you to access file content as a InputStream. See sample code below:
#Consumes("multipart/form-data")
#POST
public void post(#FormParam("file") InputStream file) {
...
}
For client side, Jersey can also help you do send HTTP request. A good sample can be found here: http://www.tuple23.com/2010/03/file-upload-using-jersey-client.html
I'm wondering if there is any way to upload files from a java program to a website that has a simple html form.
An example could look like the one on tinypic.com or bayimg.com.
Are there any Java libraries capable of performing this? Please point me in the right direction :).
Thanks.
Mike.
HTML Form uses just HTTP POST/PUT methods to upload file to server, you don't have to work/think in this case with HTML FORM, just do HTTP Connection to script and send data in required format
Read more:
http://www.jguru.com/faq/view.jsp?EID=62798
http://www.theserverside.com/news/1365153/HttpClient-and-FileUpload
http://www.java-tips.org/other-api-tips/httpclient/how-to-use-multipart-post-method-for-uploading.html
http://www.prasannatech.net/2009/03/java-http-post-file-upload-server.html
http://www.google.cz/search?aq=f&sourceid=chrome&ie=UTF-8&q=java+http+post+upload