• 大小: 1.03MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-23
  • 语言: Java
  • 标签: java  http  get  post  

资源简介

完整的java发送http包工程,可发送get及post请求。

资源截图

代码片段和文件信息

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\.settings\org.eclipse.jdt.core.prefs

     文件       3990  2018-11-14 16:50  TestURLReceive\bin\com\yao\http\Code.class

     文件       7380  2018-11-14 16:50  TestURLReceive\bin\com\yao\http\HttpRequester.class

     文件       2470  2018-11-14 16:50  TestURLReceive\bin\com\yao\http\HttpRespons.class

     文件       3450  2018-11-14 16:50  TestURLReceive\bin\com\yao\http\SinaSSOEncoder.class

     文件       1254  2018-11-14 16:50  TestURLReceive\bin\com\yao\http\Test.class

     文件    1248259  2018-11-14 16:50  TestURLReceive\plexus-encryptor-1.0-cli.jar

     文件       2984  2018-11-14 16:50  TestURLReceive\src\com\yao\http\Code.java

     文件       6781  2018-11-14 16:50  TestURLReceive\src\com\yao\http\HttpRequester.java

     文件       1828  2018-11-14 16:50  TestURLReceive\src\com\yao\http\HttpRespons.java

     文件       3042  2018-11-14 16:50  TestURLReceive\src\com\yao\http\SinaSSOEncoder.java

     文件       1388  2018-11-14 16:50  TestURLReceive\src\com\yao\http\Test.java

     目录          0  2018-11-14 16:50  TestURLReceive\bin\com\yao\http

     目录          0  2018-11-14 16:50  TestURLReceive\src\com\yao\http

     目录          0  2018-11-14 16:50  TestURLReceive\bin\com\yao

     目录          0  2018-11-14 16:50  TestURLReceive\src\com\yao

     目录          0  2018-11-14 16:50  TestURLReceive\bin\com

     目录          0  2018-11-14 16:50  TestURLReceive\src\com

     目录          0  2018-11-14 16:50  TestURLReceive\.settings

     目录          0  2018-11-14 16:50  TestURLReceive\bin

     目录          0  2018-11-14 16:50  TestURLReceive\src

     目录          0  2018-11-14 16:50  TestURLReceive

----------- ---------  ---------- -----  ----

              1284182                    24


评论

共有 条评论