Commit d0166cea authored by kiana's avatar kiana

post method updated

parent 4aeae7c2
File added
...@@ -107,7 +107,6 @@ public class Fire { ...@@ -107,7 +107,6 @@ public class Fire {
System.out.print("messageBody: " + cont + "| "); System.out.print("messageBody: " + cont + "| ");
} }
} }
} }
......
...@@ -7,12 +7,10 @@ import java.util.Scanner; ...@@ -7,12 +7,10 @@ import java.util.Scanner;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.Map; import java.util.Map;
import java.io.*; import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*; import java.util.*;
public class GetResponse { public class GetResponse implements Serializable{
Fire fire = new Fire(); Fire fire = new Fire();
Boolean include = false; Boolean include = false;
...@@ -87,7 +85,14 @@ public class GetResponse { ...@@ -87,7 +85,14 @@ public class GetResponse {
public void responseHeader(){ public void responseHeader(){
con.getHeaderField(2); Map<String, List<String>> map = con.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey() +
" ,Value : " + entry.getValue());
}
//get header by 'key'
String server = con.getHeaderField("Server");
} }
...@@ -118,7 +123,10 @@ public class GetResponse { ...@@ -118,7 +123,10 @@ public class GetResponse {
URLConnection urlConnection = url.openConnection(); URLConnection urlConnection = url.openConnection();
if (urlConnection instanceof HttpURLConnection) { if (urlConnection instanceof HttpURLConnection) {
connection = (HttpURLConnection) urlConnection; connection = (HttpURLConnection) urlConnection;
String boundary = System.currentTimeMillis() + "";
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
connection.setRequestMethod(requestType); connection.setRequestMethod(requestType);
connection.setDoOutput(true);
} }
return connection; return connection;
...@@ -128,6 +136,51 @@ public class GetResponse { ...@@ -128,6 +136,51 @@ public class GetResponse {
} }
} }
public void messageBody(String content) {
String[] message = content.trim().split("&");//splitting headers from each other
for (int j = 0; j < message.length; j++) {
String[] messageCopy = message[j].trim().split("=");//splitting key and value
String first = messageCopy[0];
String second = messageCopy[1];
con.setDoOutput(true);
con.setDoInput(true);
//con.setRequestProperty(first, second);
OutputStream os = null;
try {
os = con.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
OutputStreamWriter osw = null;
try {
osw = new OutputStreamWriter(os, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
try {
osw.write(first);
osw.write(second);
} catch (IOException e) {
e.printStackTrace();
}
try {
osw.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
osw.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
os.close();
} catch (IOException e) {
}
}
}
public void post(HttpURLConnection conn, String content){ public void post(HttpURLConnection conn, String content){
conn.setDoOutput(true); conn.setDoOutput(true);
...@@ -209,7 +262,7 @@ public class GetResponse { ...@@ -209,7 +262,7 @@ public class GetResponse {
String[] keyValueCopy = keyValue[j].trim().split(":");//splitting key and value String[] keyValueCopy = keyValue[j].trim().split(":");//splitting key and value
String key = keyValueCopy[0]; String key = keyValueCopy[0];
String value = keyValueCopy[1]; String value = keyValueCopy[1];
//con.setDoOutput(true); con.setDoOutput(true);
con.setDoInput(true); con.setDoInput(true);
con.setRequestProperty(key, value); con.setRequestProperty(key, value);
System.out.println("55555555"); System.out.println("55555555");
...@@ -285,14 +338,26 @@ public class GetResponse { ...@@ -285,14 +338,26 @@ public class GetResponse {
System.out.println("RESPONE:" + con.getRequestMethod()); System.out.println("RESPONE:" + con.getRequestMethod());
System.out.println(con.getResponseCode()); System.out.println(con.getResponseCode());
System.out.println(responseBuffer.toString()); System.out.println(responseBuffer.toString());
if (include) if (include)
responseHeader(); responseHeader();
System.out.println(con.getRequestMethod() + "100000000");
con.disconnect(); con.disconnect();
} }
catch (Exception e) { catch (Exception e) {
System.out.println( e); System.out.println( e);
// System.out.println("<html>\n" +
// "<head><title>404 Not Found</title></head>\n" +
// "<body>\n" +
// "<center><h1>404 Not Found</h1></center>\n" +
// "<hr><center>nginx/1.16.0</center>\n" +
// "</body>\n" +
// "</html>");
} }
} }
} }
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment