本文整理了Java中java.net.HttpURLConnection.setFollowRedirects()
方法的一些代码示例,展示了HttpURLConnection.setFollowRedirects()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpURLConnection.setFollowRedirects()
方法的具体详情如下:
包路径:java.net.HttpURLConnection
类名称:HttpURLConnection
方法名:setFollowRedirects
[英]Sets the flag of whether this connection will follow redirects returned by the remote server.
[中]
代码示例来源:origin: stackoverflow.com
HttpURLConnection.setFollowRedirects(false);
// note : or
// huc.setInstanceFollowRedirects(false)
代码示例来源:origin: stackoverflow.com
try {
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("HEAD");
con.setConnectTimeout(5000); //set timeout to 5 seconds
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
} catch (java.net.SocketTimeoutException e) {
return false;
} catch (java.io.IOException e) {
return false;
}
代码示例来源:origin: stackoverflow.com
import java.net.*;
import java.io.*;
public static boolean exists(String URLName){
try {
HttpURLConnection.setFollowRedirects(false);
// note : you may also need
// HttpURLConnection.setInstanceFollowRedirects(false)
HttpURLConnection con =
(HttpURLConnection) new URL(URLName).openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
代码示例来源:origin: stackoverflow.com
public static boolean exists(String URLName){
try {
HttpURLConnection.setFollowRedirects(false);
// note : you may also need
// HttpURLConnection.setInstanceFollowRedirects(false)
HttpURLConnection con =
(HttpURLConnection) new URL(URLName).openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
代码示例来源:origin: stackoverflow.com
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // Cast shouldn't fail
HttpURLConnection.setFollowRedirects(true);
// allow both GZip and Deflate (ZLib) encodings
conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
String encoding = conn.getContentEncoding();
InputStream inStr = null;
// create the appropriate stream wrapper based on
// the encoding type
if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
inStr = new GZIPInputStream(conn.getInputStream());
} else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
inStr = new InflaterInputStream(conn.getInputStream(),
new Inflater(true));
} else {
inStr = conn.getInputStream();
}
代码示例来源:origin: bumptech/glide
@After
public void tearDown() throws IOException {
HttpURLConnection.setFollowRedirects(defaultFollowRedirects);
mockWebServer.shutdown();
}
代码示例来源:origin: libgdx/libgdx
connection.setDoInput(true);
connection.setRequestMethod(method);
HttpURLConnection.setFollowRedirects(httpRequest.getFollowRedirects());
代码示例来源:origin: libgdx/libgdx
connection.setDoInput(true);
connection.setRequestMethod(method);
HttpURLConnection.setFollowRedirects(httpRequest.getFollowRedirects());
代码示例来源:origin: Dreampie/Resty
logger.info("Open connection for api " + url.getPath());
HttpURLConnection.setFollowRedirects(true);
HttpURLConnection conn;
conn = (HttpURLConnection) url.openConnection();
代码示例来源:origin: stackoverflow.com
httpURLConnection.setRequestProperty("UseCookieContainer",
"True");
HttpURLConnection.setFollowRedirects(false);
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
代码示例来源:origin: bumptech/glide
@Before
public void setUp() throws IOException {
MockitoAnnotations.initMocks(this);
defaultFollowRedirects = HttpURLConnection.getFollowRedirects();
HttpURLConnection.setFollowRedirects(false);
mockWebServer = new MockWebServer();
mockWebServer.start();
streamCaptor = ArgumentCaptor.forClass(InputStream.class);
}
代码示例来源:origin: stackoverflow.com
HttpURLConnection.setFollowRedirects( false );
代码示例来源:origin: cSploit/android
HttpURLConnection.setFollowRedirects(true);
url = new URL(mCurrentTask.url);
connection = (HttpURLConnection) url.openConnection();
代码示例来源:origin: stackoverflow.com
public static boolean exists(String URLName){
try {
HttpURLConnection.setFollowRedirects(false);
// note : you may also need
// HttpURLConnection.setInstanceFollowRedirects(false)
HttpURLConnection con =
(HttpURLConnection) new URL(URLName).openConnection();
con.setRequestMethod("HEAD");
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
代码示例来源:origin: stackoverflow.com
String url = "https://name_of_the_url"
URL request_url = new URL(url);
HttpURLConnection http_conn = (HttpURLConnection) request_url.openConnection();
HttpURLConnection.setFollowRedirects(true);
http_conn.setConnectTimeout(100000);
http_conn.setReadTimeout(100000);
http_conn.setDoOutput(true);
PrintWriter out = new PrintWriter(http_conn.getOutputStream());
if (urlparameter != null) {
out.println(urlparameter);
}
out.close();
out = null;
System.out.println(String.valueOf(http_conn.getResponseCode()));
代码示例来源:origin: stackoverflow.com
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("HEAD");
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
long date = con.getLastModified();
代码示例来源:origin: eBay/parallec
try {
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("GET");
代码示例来源:origin: ron190/jsql-injection
HttpURLConnection.setFollowRedirects(PreferencesUtil.isFollowingRedirection());
代码示例来源:origin: ron190/jsql-injection
HttpURLConnection.setFollowRedirects(PreferencesUtil.isFollowingRedirection());
代码示例来源:origin: stackoverflow.com
String address = "http://graph.facebook.com/hieu.trankim/picture";
URL url = new URL(address);
HttpURLConnection.setFollowRedirects(false); //Do _not_ follow redirects!
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
String newLocation = connection.getHeaderField("Location");
内容来源于网络,如有侵权,请联系作者删除!