可以到http://www.chinamobile.com/ZZFW/hdcx.asp?ClassID=2&ClassChild_ID=19
这个是移动网站查手机号归属地的页面。我要访问http://www.chinamobile.com/ZZFW/Search_Result.asp?ClassID=2&ClassChild_ID=19这个asp页面是post提交的,现在要加一个参数phoneNo=?请问如何通过java实现这个程序?
这个是移动网站查手机号归属地的页面。我要访问http://www.chinamobile.com/ZZFW/Search_Result.asp?ClassID=2&ClassChild_ID=19这个asp页面是post提交的,现在要加一个参数phoneNo=?请问如何通过java实现这个程序?
解决方案 »
- 一个非常简单的hql怎么写,谢谢请帮忙~(100分求答案)
- Menu中的JMenuItem被一个 ScrollPane遮挡,怎么解决?
- enum关键字问题
- jni 系统托盘右键菜单最后一项被任务栏挡住
- 请问大家的eclipse的编辑器一般选用的什么字体啊,我觉得默认的好难看啊,还有行距也小
- 怎样从X509Certificate对象得到它的base64编码?
- 有关使用Java开发代理服务器的问题向高手们请教!高手请进!
- 我用的VisualCafe不能显示中文,怎么回事呀?
- 大虾 紧急求助!!!!如何求得当前机子的处理器利用率和内存利用率?
- jb6编译时可以正确显示窗口,但是用javaw运行时却看不到窗口。疑惑。
- 如何提取word文档中的内容显示在web页面上?
- 在线等个JAVA 和SQL2000 不通过连接池的问题?
JAVA.NET包下的URL 看下 这个和JAVA其实关系不是很大,看成访问WEB
这里的,通过手机号可以查询所属地区,比如北京的就是010。我试了在链接上加上参数,但是无效,源码显示网页是通过post方式传过去的手机号。有什么方法可以解决。最好有具体的代码。谢谢
import java.net.URL;
import java.net.URLConnection;
import java.io.*;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;public class HttpRequest {
HttpURLConnection conn = null;
private static Logger elogger = Logger.getLogger("Prosten_ERROR"); public String getArea(String phone) {
String area = null;
String str = "http://www.chinamobile.com/ZZFW/Search_Result.asp?ClassID=2&ClassChild_ID=19&phoneNo="+phone;
try {
URL url = new URL("http://www.chinamobile.com/ZZFW/Search_Result.asp?ClassID=2&ClassChild_ID=19&phoneNo="+phone);
conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput( true );
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","text/xml");
conn.setRequestProperty( " Content-Length " , String.valueOf(str.length()));
conn.setDoOutput( true );
conn.setDoInput( true );
conn.connect();
int code = conn.getResponseCode();
System.out.println("code " + code); BufferedReader in = new BufferedReader( new InputStreamReader(conn.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null ) {
area += inputLine + "\n" ;
}
in.close();
}catch (Exception ex) {
elogger.error("Error:" + ex.getMessage());
return null;
}
return area;
}
public static void main(String[] args) {
PropertyConfigurator.configure("/log4j.properties");
HttpRequest t = new HttpRequest();
String str = null;
str = t.getArea("13682656987");
System.out.println("as:"+str);
}
}
上面的程序请各位看一下有什么问题,返回的getResponseCode一直是411下面str一直是null