Created
April 11, 2015 05:15
-
-
Save anonymous/1ac552bb22b542de104d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//通过第一步成功登陆后获得cookie值 | |
String cookieVal = conn.getHeaderField("Set-Cookie"); | |
String newUrlStr = "http://www.zuidaima.com/mood/create.htm"; | |
//打开新连接 | |
URL newUrl = new URL(newUrlStr); | |
HttpURLConnection newConn = (HttpURLConnection) newUrl.openConnection(); | |
newConn.setRequestMethod("POST"); | |
newConn.setDoOutput(true); | |
newConn.setDoInput(true); | |
//请求头 | |
newConn.setRequestProperty("Connection", "keep-alive"); | |
newConn.setRequestProperty("Cookie", cookieVal); | |
//要发送的内容(就像抓包那样看到的) | |
String BOUNDARY = "------WebKitFormBoundaryfV9cW5irwPumXS5m\r\n"; | |
String newSend = BOUNDARY + "Content-Disposition: form-data; name=\"content\"\r\n\r\n"; | |
newSend += "my test" + BOUNDARY; | |
newSend += "Content-Disposition: form-data; name=\"file\"; filename=\"\"\r\n"; | |
newSend += "Content-Type: application/octet-stream"; | |
newSend += "------WebKitFormBoundaryfV9cW5irwPumXS5m--\r\n"; | |
//以下是查看返回信息 | |
InputStream in = newConn.getInputStream(); | |
BufferedReader buffer = new BufferedReader(new InputStreamReader(in, "UTF-8")); | |
String s; | |
StringBuilder str = new StringBuilder(); | |
while ((s = buffer.readLine()) != null) { | |
str.append(s); | |
} | |
System.out.print(newConn.getResponseCode() + "\n" + str.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment