HttpClient

tags: Mobile  ASP.net  ASP  Eclipse  program

HttpClient is a sub-project under Apache Jakarta Common that can be used to provide efficient, up-to-date, feature-rich client programming toolkits that support the HTTP protocol, and it supports the latest HTTP protocol. Version and recommendations.
Currently the latest version of HttpClient is HttpClient 4.0.1 (GA), download page: [url]http://hc.apache.org/downloads.cgi[/url]
The following test survey examples assume that the user has logged in:
Example: Query information by mobile phone number ([url]http://www.ip138.com:8080/search.asp?[/url])
Webpage code
FORM action="" method="get" name="mobileform" onsubmit="return checkMobile();">
<TR bgColor=#eff1f3class=tdc>
<TD align=middle width=130 noswap>Mobile number (segment) </TD>
[color=blue]<TD align=middle width=*><INPUT class=tdc name="mobile" maxLength="11">[/color][color=red]<!--Find the input box name from the url Can also be seen -->[/color]
<INPUT name="action" type="hidden" value=mobile> <INPUT class=bdtj name=B1 type=submit value="Query"></TD>
</TR>
</FORM>
<TR class=tdc bgcolor=#EFF1F3>
<TD width="130" align="center" noswap>Mobile number segment you are querying</TD>
<TD width=* align="center" class=tdc2>13601695</TD>
</TR>
<TR class=tdc bgcolor=#EFF1F3>
<TD width="130" align="center" noswap> card number attribution</TD>
<TD width=* align="center" class=tdc2>Shanghai Shanghai</TD>
</TR>
<TR class=tdc bgcolor=#EFF1F3>
<TD width="130" align="center" noswap> card type </TD>[color=red]<!--display data, the common point for class is tdc2, which can be filtered in the process of analyzing html Standard -->[/color]
[color=blue]<TD width=* align="center" class=tdc2>Mobile Global Card</TD>[/color]
</TR>
<TR class=tdc bgcolor=#EFF1F3>
<TD align="center">Area code</TD>
[color=blue]<TD align="center" class=tdc2>021</TD>[/color]
</TR>
<TR class=tdc bgcolor=#EFF1F3>
<TD align="center">Postcode</TD>
<[color=blue]TD align="center" class=tdc2>200000</TD>[/color]
The above analysis, the necessary conditions for using HttpClient: url, parameters, and htmlparser filter conditions
Using the HttpClient query, in order to analyze the extracted html content, we use the htmlparser package, its home page: http://htmlparser.sourceforge.net/
Create a Telephone class in Eclipse, in addition to main (), including 2 methods:
Call HttpClient, get the responseString from the specified url and return.
Call HtmlParser to parse the html file:
public static String getPostString(String mobile) throws HttpException, IOException
{
HttpClient hc=new HttpClient();
PostMethod pm=new PostMethod("http://www.ip138.com:8080/search.asp"); /*Search page url*/
hc.getParams().setContentCharset("gb2312");
pm.addParameter("mobile",mobile); /*Retrieve the parameters of the page 1*/
pm.addParameter("action","mobile"); /*Retrieve the parameters of the page 2*/
hc.executeMethod(pm);
System.out.println("GET POST STRING: "+pm.getResponseBodyAsString());
return pm.getResponseBodyAsString();
}
public static void getMobileInfor(String poststring) throws ParserException
{
Parser parser=new Parser(poststring);
NodeList nodelist=null;
NodeFilter filter=new HasAttributeFilter("class","tdc2"); /*Filters the content of the page and extracts the content of class tdc2*/
nodelist=parser.extractAllNodesThatMatch(filter);
for(int i=0;i<nodelist.size();i++)
{
System.out.println("data"+i+ ":"+nodelist.elementAt(i).toPlainTextString().replace(" ",""));
}
}

View the results of the operation as follows
Recommend a good place to learn HttpClient [url]http://htmlparser.com.cn/post/20090816119.html[/url]

Intelligent Recommendation

The configuration system of .NET COR

First of all, the configuration system ofnetcore is currently the most commonly -based configuration, such as JSON, XML files, and of course there are other commandline, EnvironmentVariables. 1. First...

SpringBoot uses AOP+Redis to implement a simple token login verification example

Create a SpringBoot project and introduce dependencies The idea is this: 1. When the user logs in successfully, a Token is randomly created, and then stored in the session and Redis respectively 2. Co...

LintCode 1005. JavaScript algorithm for the maximum area of ​​a triangle

description There are a series of points on the plane. Returns the largest area of ​​a triangle that can be formed by three points. Description 3 <= points.length <= 50. The points will not be r...

Web framework Django learning record (2) show the contents of the database in the page on the page

1. Create a project, apply 2. Modify configuration Modify YU1 \ YU1 \ Settings.py file installed_apps, add a line 'yuapp', templates, modify 'DIRS': [Base_Dir + "/ Templates",], 3. Modify YU...

In-depth analysis of HashSet and HashMap source code

HashSet source code analysis: Let’s take a look at its construction method: Uh~~ Its underlying layer is actually implemented using HashMap, subverting the three views. So how is it used? Contin...

More Recommendation

ZooKeeper Register Service Information --- Get IP Address and Idle Port (NodeJS TypeScript)

This object is column to write the 2017-19 update repair multi-NIC to get IP issues. Function call getIdleport (Callback: (portback: (port: Number, IP ?: string) => void)Winning this airline port i...

[Interview Question 04 10] Check the subtree

topic Topic link Check the subtree. You have two very large binary trees: T1, with tens of thousands of nodes; T2, with tens of thousands of nodes. Design an algorithm to determine whether T2 is a sub...

Python insertion sort

Introduction The working principle of insertion sort is that for each unsorted data, insert it into the previously sorted data, and compare the insertion from back to front step: Starting from the fir...

Android uses PopupWindow to implement the reuse class of pop-up warning boxes

Please indicate the source for reprinting: In Android development, I believe that everyone is familiar with the interface shown in the figure below, and the frequency of use of this pop-up box is also...

JS carousel map - seamless scrolling

JS carousel map – seamless scrolling Use the relative positioning to change the left value to achieve the carousel scrolling effect....

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top