Atitit.http get post principle and framework implementation java PHP
1. Related Settings 1
1.1. UrlEncode 1
1.2. Encoding of the output stream 1
1.3. Picture, post of file 1
2. Get is simple only text string 1
3. Post Byte stream (Basic) 1
4. Post text ( with code) 2
5. Framework for sending http requests 2
5.1. JDK URLConnection 2
5.2. JDK HttpURLConnection 2
5.3. Apache HttpClient 2
5.4. HTTP Browser 3
6. Reference 3
1. Related Settings 1.1. urlencode1.2. Encoding of the output stream 1.3. Pictures, Files ofPost
2. Getrelatively simple is just a string of words
Doesn't seem to have a coding problem.
3. Postbyte stream (base)
public static string sendpost (string URL, byte [] bytes)
Author:: Old Wow's paw attilax Ayron, email:[email protected]
Reprint please indicate source: Http://blog.csdn.net/attilax
4. Posttext ( withcode)
OutputStream OutputStream = Conn . Getoutputstream ();
outputstream. Write (param. getBytes ("UTF-8" ));
//Flush output stream buffering
outputstream. Flush ();
5. Send HTTPframework of the request5.1. JDK URLConnection
Java has native APIs that can be used to send HTTP requests, Java.net.URL, java.net.URLConnection, which are useful and common, but not simple enough
5.2. JDK HttpURLConnection
is the standard class for Java ,httpurlconnection inherits from URLConnectionand can be used to send to a specified Web site GET requests, POST request. It provides the following convenient methods on the basis of URLConnection:
· int Getresponsecode (): Gets the response code of the server.
· String getresponsemessage (): Gets the response message for the server.
· String Getresponsemethod (): Gets the method that sent the request.
· void Setrequestmethod (String method): Sets the method for sending requests
5.3. Apache HttpClient
In general, if only needed web A simple page of the site submits the request and gets the server response, httpurlconnection web site pages may not be so simple, These pages are not accessible through a simple url Users may be required to log on and have the appropriate permissions to access the page. In this case , you need to involve session Span style= "font-family:arial" >cookie If you intend to use httpurlconnection
in order to deal better with the Web site requests, including processing Session , Cookies and other details . Apache The Open source organization provides a HttpClient project, look at its name and know that it is a simple HTTP The client (not the browser) can be used to send HTTP requests to receive HTTP responses. However, the server's response is not cached, JavaScript code embedded in the HTML page cannot be executed, and the content of the page is not parsed or processed
5.4. HTTP Browser
6. Reference
The difference between httpurlconnection and HttpClient in Java network connection - Bloom Winter - Blog Channel -CSDN.NET.htm
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Atitit.http get post principle and framework implementation Java PHP