");Conn.setrequestproperty ("User-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ");To send a POST request, you must set the following two linesConn.setdooutput (TRUE);Conn.setdoinput (TRUE);Gets the output stream corresponding to the URLConnection objectout = new PrintWriter (Conn.getoutputstream ());Send Request parametersOut.print (param);Buffer for flush output streamOut.flush ();Defines the response of the BufferedReader input st
The students who use URLConnection to crawl should use this right from the start. OK, back to the chase ...In the content of Chinese, English has been normal display, there will still be some Chinese or English garbled, this is why? This problem has been hovering in the heart ... Real TM's Egg hurts ....There is a solution on the Internet, in fact, this with you to start learning with the use of Java information.Most of the online code is as follows:B
Create a web project under myeclipse named URL. Create a new welcome. jsp under webroot. The code in the body tag is:
name=
Create a package under SRC and write the urlconnectionsendpostrequest class. The Code is as follows;
public class URLConnectionSendPostRequest {public static void main(String[] args) throws Exception {String s=sendPost("http://localhost:8080/url/welcome.jsp","name=tompass=1234");System.out.println(s);}public static String sendPost(String url,String param) throws Exception{
UrlPackage Org.urldemo;Import Java.io.InputStream;Import Java.net.URL;Import Java.util.Scanner;public class Urldemo {public static void Main (string[] args) throws exception{URL url = new URL ("http", "www.hut.edu.cn", "/cn/xxgk/xxgk.asp");InputStream input = Url.openstream ();Scanner scan = new Scanner (input);Scan.usedelimiter ("\ n");while (Scan.hasnext ()) {System.out.println (Scan.next ());}}}Run Result: The displayed content is HTML code.The content downloaded in the above program is all t
Close_wait Description: http://blog.csdn.net/talent210/article/details/65434677
httpclient
Improper use of Httpclien will produce a large number of close_wait
Workaround:
First, the client actively shut down the connection
1, use shutdown parameter
JDK documentation rarely introduces the use of proxy servers. It is said that jdk5.0 seems to have added this content. In fact, it is very easy to use the proxy server, as long as you add the followingCodeYou can:
Properties prop =System.
Access to the network requires internet access: Android.permission.INTERNETuse URLConnection to request a URL address for content://1. Creating a URL objecturl url = new URL (url_str);//2. getting a URLConnection objecthttpurlconnection connection =
) { e2.printstacktrace (); } } In Java. Close is the meaning of closing. such as Session.close (); It means to close the session and free up memory.There are also commonly used links to the database connection After use, that is, the end of a function code , at the same time write Connection.close (); free memory6.new// to turn a string into a URL object NewFor example, there are now two classes, T1 and T
Python decorator use example and actual application example, python example
Test 1
Deco is running, but myfunc is not running
Copy codeThe Code is as follows:Def deco (func ):Print 'before func'Return func
Def myfunc ():Print 'myfunc () called'Myfunc = deco (myfunc)
Test 2
Call myfunc in the required deco to executeCopy codeThe Code is as follows:Def deco (func
Network multiline thread download and merge file example, multiline thread merge example
In this example, I/O streams and multiple threads are used to download the same image. After the download is completed, the thread creation method is used to control the execution time of the main thread, that is, the method called by the main thread, create a thread in the m
/*======================================================================
A Globalmem Driver As an example of char device drivers
There are two same globalmems in this driver
This example was to introduce the function of File->private_data
The initial developer of the original code is Baohua Song
======================================================================*/
#include #include #include #include #in
We will find an example of using HttpClient to send a Post request in jsp. If you do not need any more, please refer to it.
The company wants to encapsulate its own product into a WebService platform, so it recently began to learn how to use Java to send Http request content. This section was previously written in PHP and used in most basic sockets and third-party plug-ins.
I learned two Java Methods: java.net. UR
interested in the response content itself. But if the response body is a long and you aren't interested in the rest of it after seeing the beginning, you can close th E InputStream. But the need to is aware that more data could is on the its-to-the-. Thus the connection may is cleared for reuse.Here's a code example that complies to the above recommendation:try {url a = new URL (args[0]); URLConnection
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.