java 방향 을 바 꾼 url 가 져 오기
package com.numberone.master.modules.test;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
public class GetPostTest {
public static String sendGet(String url) {
String result = "";
String urlName = url;
try {
URL realURL = new URL(urlName);
URLConnection conn = realURL.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
conn.connect();
Map> map = conn.getHeaderFields();
for (String s : map.keySet()) {
System.out.println(s + "-->" + map.get(s));
}
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String line;
while ((line = in.readLine()) != null) {
result += "
" + line;
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public static String sendPost(String url,String param){
String result = "";
HttpURLConnection conn = null;
try {
URL realUrl = new URL(url);
conn = (HttpURLConnection) realUrl.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36");
conn.setInstanceFollowRedirects(true);
conn.setRequestProperty("Connection", "Keep-Alive");//
conn.setInstanceFollowRedirects(true);
conn.setInstanceFollowRedirects(false);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//post
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setDoOutput(true);// , outputStream
//PrintWriter out = new PrintWriter(conn.getOutputStream());
//out.print(param);
PrintWriter out =new PrintWriter(conn.getOutputStream());
//out.write(param);
out.print(param); //
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8"));//
String line;
while((line = in.readLine()) != null){
result +="
" + line;
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
String param = "Search%2FAirlineMode=false&Search%2FcalendarCacheSearchDays=60&Search%2FcalendarSearched=false&dropOffLocationRequired=false&Search%2FsearchType=F&searchTypeValidator=F&xSellMode=false&Search%2FflightType=oneway&destinationLocationSearchBoxType=L&Search%2FisUserPrice=1&Search%2FOriginDestinationInformation%2FOrigin%2Flocation=CITY_BJS_CN&Search%2FOriginDestinationInformation%2FOrigin%2Flocation_input=%E5%8C%97%E4%BA%AC&Search%2FOriginDestinationInformation%2FDestination%2Flocation=CITY_CTU_CN&Search%2FOriginDestinationInformation%2FDestination%2Flocation_input=%E6%88%90%E9%83%BD&Search%2FDateInformation%2FdepartDate_display=2018-09-06&Search%2FDateInformation%2FdepartDate=2018-09-06&Search%2FDateInformation%2FreturnDate=2018-09-05&Search%2FcalendarSearch=false&Search%2FPassengers%2Fadults=1&Search%2FPassengers%2Fchildren=0&Search%2FpromotionCode=";
//String param = "";
String sendRecvPost =GetPostTest.sendPost("http://flights.sichuanair.com/3uair/ibe/common/processSearchForm.do",param);
System.out.println(sendRecvPost);
}
}
전송 소스:https://www.52pojie.cn/thread-791217-1-1.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.