完整的java发送http包工程,可发送get及post请求。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 368 2018-11-14 16:50 TestURLReceive.classpath
文件 390 2018-11-14 16:50 TestURLReceive.project
文件 598 2018-11-14 16:50 TestURLReceive.settingsorg.eclipse.jdt.core.prefs
文件 3990 2018-11-14 16:50 TestURLReceiveincomyaohttpCode.class
文件 7380 2018-11-14 16:50 TestURLReceiveincomyaohttpHttpRequester.class
文件 2470 2018-11-14 16:50 TestURLReceiveincomyaohttpHttpRespons.class
文件 3450 2018-11-14 16:50 TestURLReceiveincomyaohttpSinaSSOEncoder.class
文件 1254 2018-11-14 16:50 TestURLReceiveincomyaohttpTest.class
文件 1248259 2018-11-14 16:50 TestURLReceiveplexus-encryptor-1.0-cli.jar
文件 2984 2018-11-14 16:50 TestURLReceivesrccomyaohttpCode.java
文件 6781 2018-11-14 16:50 TestURLReceivesrccomyaohttpHttpRequester.java
文件 1828 2018-11-14 16:50 TestURLReceivesrccomyaohttpHttpRespons.java
文件 3042 2018-11-14 16:50 TestURLReceivesrccomyaohttpSinaSSOEncoder.java
文件 1388 2018-11-14 16:50 TestURLReceivesrccomyaohttpTest.java
目录 0 2018-11-14 16:50 TestURLReceiveincomyaohttp
目录 0 2018-11-14 16:50 TestURLReceivesrccomyaohttp
目录 0 2018-11-14 16:50 TestURLReceiveincomyao
目录 0 2018-11-14 16:50 TestURLReceivesrccomyao
目录 0 2018-11-14 16:50 TestURLReceiveincom
目录 0 2018-11-14 16:50 TestURLReceivesrccom
目录 0 2018-11-14 16:50 TestURLReceive.settings
目录 0 2018-11-14 16:50 TestURLReceivein
目录 0 2018-11-14 16:50 TestURLReceivesrc
目录 0 2018-11-14 16:50 TestURLReceive
----------- --------- ---------- ----- ----
1284182 24
package com.yao.http;
import java.util.linkedHashMap;
import java.util.Map;
import java.io.*;
import java.net.*;
public class Code {
String urlString = “http://login.sina.com.cn/sso/prelogin.php?entry=miniblog&callback=sinaSSOController.preloginCallBack&su=d3VxaW5nY2hlbnhpbmRhJTQwMTYzLmNvbQ%3D%3D&client=ssologin.js(v1.3.12)“;
StringBuffer input = new StringBuffer();
String email=“email“;
String password=“password“;
String entry=“weibo“;
String gateway=“1“;
String from=““;
String savestate=“7“;
String useticket=“1“;
String ssosimplelogin=“1“;
String vsnf=“1“;
String vsnval=““;
String su=“d3VxaW5nY2hlbnhpbmRhJTQwMTYzLmNvbQ%3D%3D“;
String service=“miniblog“;
String servertime;
String nonce;
String pwencode=“wsse“;
String sp;
String encoding=“UTF-8“;
String url=“http%3A%2F%2Fweibo.com%2Fajaxlogin.php%3Fframelogin%3D1%26callback%3Dparent.sinaSSOController.feedBackUrlCallBack“;
String returntype=“meta“;
public Map post() throws UnsupportedEncodingException MalformedURLException IOException{
Getinformation();
Map map = new linkedHashMap();
map.put(“entry“this.entry);
map.put(“gateway“this.gateway);
map.put(“from“this.from);
map.put(“savestate“this.savestate);
map.put(“useticket“this.useticket);
map.put(“ssosimplelogin“this.ssosimplelogin);
map.put(“vsnf“this.vsnf);
map.put(“vsnval“this.vsnval);
map.put(“su“this.su);
map.put(“service“this.service);
map.put(“servertime“servertime);
map.put(“nonce“nonce);//需要调整
map.put(“pwencode“this.pwencode);
map.put(“sp“getSp(this.password this.servertime this.nonce));
map.put(“encoding“this.encoding);
map.put(“url“this.url);
map.put(“returntype“this.returntype);
return map;
}
public void Getinformation() throws UnsupportedEncodingException MalformedURLException IOException
{
InputStreamReader in = new InputStreamReader(new URL(this.urlString).openStream()“UTF-8“);
int ch;
while((ch = in.read())!=-1)
this.input.append((char)ch);
this.servertime=getServerTime(“servertime“);
this.nonce=getServerTime(“nonce“);
}
public String getServerTime(String method) {
int i=this.input.indexOf(“:“this.input.indexOf(method));
int n = 0;
if(method.equalsIgnoreCase(“servertime“))
{
n=this.input.indexOf(““i);
this.servertime=this.input.substring(i+1n);
i++;
}
else if(method.equalsIgnoreCase(“nonce“))
{
n=this.input.indexOf(“““ i+6);
this.nonce=this.input.substring(i+2n);
i=i+2;
}
System.out.println(this.input);
return this.input.substring(in);
}
public String getSp(String pwd String servertime String nonce){
String sp = new SinaSSOEncoder().encode(pwd servertime nonce);
return sp;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 368 2018-11-14 16:50 TestURLReceive.classpath
文件 390 2018-11-14 16:50 TestURLReceive.project
文件 598 2018-11-14 16:50 TestURLReceive.settingsorg.eclipse.jdt.core.prefs
文件 3990 2018-11-14 16:50 TestURLReceiveincomyaohttpCode.class
文件 7380 2018-11-14 16:50 TestURLReceiveincomyaohttpHttpRequester.class
文件 2470 2018-11-14 16:50 TestURLReceiveincomyaohttpHttpRespons.class
文件 3450 2018-11-14 16:50 TestURLReceiveincomyaohttpSinaSSOEncoder.class
文件 1254 2018-11-14 16:50 TestURLReceiveincomyaohttpTest.class
文件 1248259 2018-11-14 16:50 TestURLReceiveplexus-encryptor-1.0-cli.jar
文件 2984 2018-11-14 16:50 TestURLReceivesrccomyaohttpCode.java
文件 6781 2018-11-14 16:50 TestURLReceivesrccomyaohttpHttpRequester.java
文件 1828 2018-11-14 16:50 TestURLReceivesrccomyaohttpHttpRespons.java
文件 3042 2018-11-14 16:50 TestURLReceivesrccomyaohttpSinaSSOEncoder.java
文件 1388 2018-11-14 16:50 TestURLReceivesrccomyaohttpTest.java
目录 0 2018-11-14 16:50 TestURLReceiveincomyaohttp
目录 0 2018-11-14 16:50 TestURLReceivesrccomyaohttp
目录 0 2018-11-14 16:50 TestURLReceiveincomyao
目录 0 2018-11-14 16:50 TestURLReceivesrccomyao
目录 0 2018-11-14 16:50 TestURLReceiveincom
目录 0 2018-11-14 16:50 TestURLReceivesrccom
目录 0 2018-11-14 16:50 TestURLReceive.settings
目录 0 2018-11-14 16:50 TestURLReceivein
目录 0 2018-11-14 16:50 TestURLReceivesrc
目录 0 2018-11-14 16:50 TestURLReceive
----------- --------- ---------- ----- ----
1284182 24
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)