Forums Register Login

Get vs Post

+Pie Number of slices to send: Send
Can anyone explain the real differences between get and a post.
a. This is what I did.
II wrote a program using Get and did somethoing like :
PrintWriter out = new PrintWriter();
out.print("GET " +url+ "HTTP/r/r/n");
In this case the program returns me the html in the page . Now when I do:
PrintWriter out = new PrintWriter();
out.print("POST " +url+ "HTTP/r/r/n");
the program works but it does not return anything.

Can anyone explain how get and post differ and how they work internally?
Thanks.
Chiran
+Pie Number of slices to send: Send
Can you show us your program that you wrote? (Remember to use the <CODE> attributes)
+Pie Number of slices to send: Send
Code is:
Do not woryy about the SSL code, Just look at the GET vs POST. GEt always retyurns something but POST doesn't
<CODE>
public void run() throws Exception {
String thisLine;
// Get a SocketFactory object for creating SSL sockets
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
// Create a secure socket connected to the HTTPS port (port 443) of a server
SSLSocket sslsock = (SSLSocket) factory.createSocket("iweb.verizon.com", 443);
//SSLSocket sslsock = (SSLSocket) factory.createSocket("java.sun.com", 443);
// Get the certificate presented by the web server. This may throw an
// exception if the server didn't supply a certificate. Look at the
// issuer of the certificate and decide if it is trusted.
SSLSession session = sslsock.getSession();
X509Certificate cert = (X509Certificate)session.getPeerCertificateChain()[0];
String issuer = cert.getIssuerDN().getName();
// Assuming we trust the certificate, we now use the socket just like a normal
// java.net.Socket object. So send a HTTP request and read the response
PrintWriter out = new PrintWriter(sslsock.getOutputStream());
//out.print("GET " + "/j2se/1.4/docs/api/java/lang/IllegalArgumentException.html" + " HTTP/1.0\r\n");
out.write("POST " + "/eweb/secure/web/jsp/index.jsp" + " HTTP/1.0\r\n\r\n");
out.flush();

// Next, read the server's response and print it to the console.
BufferedReader in =
new BufferedReader(new InputStreamReader(sslsock.getInputStream()));
String line;
while((line = in.readLine()) != null) System.out.println(line);
out.close();
// Finally, close the socket.
sslsock.close();
</CODE>

}
+Pie Number of slices to send: Send
well, if your program sends a HTTP Get request, and the request url is a html page, then you will see that html page. if the url is a servlet, or jsp, you will see what the doGet() responses. if the doGet writes something, you see it, if it writes nothing, you see nothing. (you got only Http status code and Http headers)
if your program sends a HTTP Post request, but the url(in your program it is a jsp page) does not generate any response, then you got nothing.
both Get and Post could generate responses, binary or text, but it could just response with Http status code and Http headers, with no content returned. Depend on what the requested url does.
I am not sure if I am answering the stuff you want to know.
+Pie Number of slices to send: Send
This URL when using GET returns the html. However when using POST it doesn't return anything. That's what I cannot understand.
+Pie Number of slices to send: Send
a static resource can't handle a POST request.
web server receives the HTTP request.
If the requested url is a static resource,
if it is a GET, web server will return that resource.
if it is a POST, what will be returned depends on the web server. it may be status_code 405, for example.
If the requested url is a dynamic resource, say a Servlet or jsp, web server will let the dynamic resouce handle the request. No matter whether it is GET, POST, PUT, DELETE and other HTTP requests.
POST means "I give you this posted data, you process it for me, and return me the result". static resources can't process the POST request.
GET means, "hey web server, give me that url".
+Pie Number of slices to send: Send
Cool, I got it Kyle great explanation.
Destroy anything that stands in your way. Except this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1479 times.
Similar Threads
Get vs Post
Non Blocking HttpPost Request / Client-Server communication
HTML form created by Java
compatibility of date format
Delete Records from MS Access Database
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:46:30.