本文整理汇总了Java中java.net.URLConnection.setDoInput方法的典型用法代码示例。如果您正苦于以下问题:Java URLConnection.setDoInput方法的具体用法?Java URLConnection.setDoInput怎么用?Java URLConnection.setDoInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URLConnection
的用法示例。
在下文中一共展示了URLConnection.setDoInput方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRequest
import java.net.URLConnection; //导入方法依赖的package包/类
private static URLConnection createRequest(String strUrl, String strMethod) throws Exception {
URL url = new URL(strUrl);
URLConnection conn = url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
if (conn instanceof HttpsURLConnection) {
HttpsURLConnection httpsConn = (HttpsURLConnection) conn;
httpsConn.setRequestMethod(strMethod);
httpsConn.setSSLSocketFactory(getSSLSF());
httpsConn.setHostnameVerifier(getVerifier());
} else if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod(strMethod);
}
return conn;
}
示例2: getCollectionDocumentFromWebService
import java.net.URLConnection; //导入方法依赖的package包/类
private Document getCollectionDocumentFromWebService ( String _key )
{
Document collectionDocument = null;
// make the call to DDS and get ListCollections
try {
URLConnection connection = new URL ("http://www.dlese.org/dds/services/ddsws1-1?verb=Search&ky=" + _key + "&n=200&s=0" ).openConnection();
connection.setDoOutput( true );
connection.setDoInput(true);
((HttpURLConnection)connection).setRequestMethod("GET");
SAXReader xmlReader = new SAXReader();
collectionDocument = xmlReader.read(connection.getInputStream());
} catch ( Exception e ) {
e.printStackTrace();
}
return collectionDocument;
}
示例3: actionPerformed
import java.net.URLConnection; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent ae) {
try {
String uname = tf1.getText();
String upwd = tf2.getText();
String url = "http://localhost:7001/loginapp/login?uname="+uname+"&upwd="+upwd;
URL u = new URL(url);
URLConnection uc = u.openConnection();
uc.setDoInput(true);
uc.setDoOutput(true);
InputStream is = uc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
response = br.readLine();
repaint();
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: post
import java.net.URLConnection; //导入方法依赖的package包/类
public static String post(URLConnection connection,
String stringWriter,
Credentials credentials) throws Exception {
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Authorization",
"Basic "
+ Base64.encode((credentials.getUserName() + ":" + new String(
credentials.getPassword())).getBytes()));
OutputStreamWriter postData = new OutputStreamWriter(connection.getOutputStream());
postData.write(stringWriter);
postData.flush();
postData.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = "";
String line = "";
while ((line = in.readLine()) != null)
response = response + line;
in.close();
return response;
}
示例5: postYbApi
import java.net.URLConnection; //导入方法依赖的package包/类
public String postYbApi(String apiName,String query) throws IOException {
String url = "https://openapi.yiban.cn/" + apiName;
String charset = "UTF-8";
URLConnection connection = new URL(url).openConnection();
connection.setRequestProperty("Accept-Charset", charset);
connection.setDoOutput(true);
connection.setDoInput(true);
PrintWriter out = new PrintWriter(connection.getOutputStream());
out.print(query);
out.flush();
InputStream response = connection.getInputStream();
StringBuilder sb=new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(response));
String read;
while((read=br.readLine()) != null) {
sb.append(read);
}
br.close();
return sb.toString();
}
示例6: uploadURL
import java.net.URLConnection; //导入方法依赖的package包/类
private static URL uploadURL(URL url) throws IOException {
assert(!EventQueue.isDispatchThread());
File tmpFile = File.createTempFile("loading", ".html"); //NOI18N
tmpFile.deleteOnExit();
FileOutputStream fw = new FileOutputStream(tmpFile);
try{
URLConnection conn = url.openConnection();
conn.setReadTimeout(200000);
conn.setDoOutput(false);
conn.setDoInput(true);
conn.setRequestProperty("User-Agent", "NetBeans"); //NOI18N
InputStream is = conn.getInputStream();
if (is == null) {
throw new IOException("Null input stream from "+conn);
}
try{
while(true) {
int ch = is.read();
if (ch == -1) {
break;
}
fw.write(ch);
}
}finally{
is.close();
}
}finally{
fw.close();
}
return Utilities.toURI(tmpFile).toURL();
}
示例7: getStockQuotes
import java.net.URLConnection; //导入方法依赖的package包/类
public Collection<StockQuote> getStockQuotes ( final Collection<String> symbols )
{
try
{
final URL url = generateURL ( symbols );
final URLConnection connection = url.openConnection ();
connection.setDoInput ( true );
return parseResult ( symbols, connection.getInputStream () );
}
catch ( final Throwable e )
{
return failAll ( symbols, e );
}
}
示例8: getImpl
import java.net.URLConnection; //导入方法依赖的package包/类
@SuppressWarnings ({ "unchecked", "rawtypes" })
@Override
public Object getImpl (Class api)
{
if (api.isAssignableFrom(InputStream.class))
{
try
{
URLConnection urlConnect = this.url.openConnection();
if (this.url.getUserInfo () != null)
{
// HTTP Basic Authentication.
String userpass = this.url.getUserInfo ();
String basicAuth = "Basic " +
new String(new Base64 ().encode (userpass.getBytes ()));
urlConnect.setRequestProperty ("Authorization", basicAuth);
}
urlConnect.setDoInput(true);
urlConnect.setUseCaches(false);
return urlConnect.getInputStream();
}
catch (IOException e)
{
return null;
}
}
return null;
}
示例9: getCollectionKeyFromDDS
import java.net.URLConnection; //导入方法依赖的package包/类
public String getCollectionKeyFromDDS( String _collectionName )
{
String collectionKey = null;
// make the call to DDS and get ListCollections
try {
URLConnection connection = new URL ("http://www.dlese.org/dds/services/ddsws1-1?verb=ListCollections" ).openConnection();
connection.setDoOutput( true );
connection.setDoInput(true);
((HttpURLConnection)connection).setRequestMethod("GET");
Map<String,String> uris = new HashMap<String,String>();
uris.put( "ddsws", "http://www.dlese.org/Metadata/ddsws" );
uris.put( "ddswsnews", "http://www.dlese.org/Metadata/ddswsnews" );
uris.put( "groups", "http://www.dlese.org/Metadata/groups/" );
uris.put( "adn", "http://adn.dlese.org" );
uris.put( "annotation", "http://www.dlese.org/Metadata/annotation" );
XPath xpath = DocumentHelper.createXPath( "//collections/collection[vocabEntry=\"" + _collectionName + "\"]/searchKey/text()" );
xpath.setNamespaceURIs( uris );
SAXReader xmlReader = new SAXReader();
this.document = xmlReader.read(connection.getInputStream());
Text t = ((Text)xpath.selectSingleNode(this.document));
collectionKey = t.getStringValue();
} catch ( Exception e ) {
e.printStackTrace();
}
return collectionKey;
}
示例10: completeRequest
import java.net.URLConnection; //导入方法依赖的package包/类
/**
* Performs any additional processing necessary to complete the request.
**/
protected void completeRequest( URLConnection connection ) throws IOException {
super.completeRequest( connection );
connection.setDoInput( true );
connection.setDoOutput( true );
OutputStream stream = connection.getOutputStream();
writeMessageBody( stream );
stream.flush();
stream.close();
}
示例11: completeRequest
import java.net.URLConnection; //导入方法依赖的package包/类
/**
* Performs any additional processing necessary to complete the request.
**/
protected void completeRequest( URLConnection connection ) throws IOException {
((HttpURLConnection) connection).setRequestMethod( getMethod() );
connection.setDoInput( true );
connection.setDoOutput( true );
OutputStream stream = connection.getOutputStream();
writeMessageBody( stream );
stream.flush();
stream.close();
}
示例12: createOutputStream
import java.net.URLConnection; //导入方法依赖的package包/类
public static OutputStream createOutputStream(String uri) throws IOException {
// URI was specified. Handle relative URIs.
final String expanded = XMLEntityManager.expandSystemId(uri, null, true);
final URL url = new URL(expanded != null ? expanded : uri);
OutputStream out = null;
String protocol = url.getProtocol();
String host = url.getHost();
// Use FileOutputStream if this URI is for a local file.
if (protocol.equals("file")
&& (host == null || host.length() == 0 || host.equals("localhost"))) {
File file = new File(getPathWithoutEscapes(url.getPath()));
if (!file.exists()) {
File parent = file.getParentFile();
if (parent != null && !parent.exists()) {
parent.mkdirs();
}
}
out = new FileOutputStream(file);
}
// Try to write to some other kind of URI. Some protocols
// won't support this, though HTTP should work.
else {
URLConnection urlCon = url.openConnection();
urlCon.setDoInput(false);
urlCon.setDoOutput(true);
urlCon.setUseCaches(false); // Enable tunneling.
if (urlCon instanceof HttpURLConnection) {
// The DOM L3 REC says if we are writing to an HTTP URI
// it is to be done with an HTTP PUT.
HttpURLConnection httpCon = (HttpURLConnection) urlCon;
httpCon.setRequestMethod("PUT");
}
out = urlCon.getOutputStream();
}
return out;
}
示例13: post
import java.net.URLConnection; //导入方法依赖的package包/类
public String post(String url, String params) {
String result = "";
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
// conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible;
// MSIE 6.0; Windows NT 5.1;SV1)");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
try (PrintWriter out = new PrintWriter(conn.getOutputStream())) {
// 发送请求参数
out.print(params);
// flush输出流的缓冲
out.flush();
}
// 定义BufferedReader输入流来读取URL的响应
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
String line;
while ((line = in.readLine()) != null) {
result += line;
}
}
} catch (Exception e) {
throw new ZhhrUtilException("发送POST请求出现异常!原因:" + e.getMessage());
}
return result;
}
示例14: doGet
import java.net.URLConnection; //导入方法依赖的package包/类
/**
* Override of HttpServlet.doGet()
*/
@Override
protected void doGet(
HttpServletRequest request,
HttpServletResponse response
) throws ServletException, IOException
{
ResourceLoader loader = _getResourceLoader(request);
String resourcePath = getResourcePath(request);
URL url = loader.getResource(resourcePath);
// Make sure the resource is available
if (url == null)
{
_logURLNotFound(request, loader, resourcePath);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// Stream the resource contents to the servlet response
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(false);
//We need to do a connect here. Some connections, like file connections and
//whatnot may have header information right away. Other connections, like
//to external resources, will not have been able to connect until this is called.
//The reason this worked before is the getInputStream implicitly called the
//connect, but the header information which was returned would before the stream
//was obtained would not be avialble.
connection.connect();
_setHeaders(connection, response, loader);
InputStream in = connection.getInputStream();
OutputStream out = response.getOutputStream();
byte[] buffer = new byte[_BUFFER_SIZE];
try
{
_pipeBytes(in, out, buffer);
}
finally
{
try
{
in.close();
}
finally
{
out.close();
}
}
}
示例15: invoke
import java.net.URLConnection; //导入方法依赖的package包/类
public PropBagEx invoke(BlackBoardSessionData data, String servlet, String name, Collection<NameValue> parameters)
throws IOException
{
long startTime = System.currentTimeMillis();
BlindSSLSocketFactory.register();
// Setup URLConnection to appropriate servlet/jsp
URLConnection con = new URL(this.url, servlet).openConnection();
con.setConnectTimeout(TIMEOUT);
con.setReadTimeout(TIMEOUT);
con.setDoInput(true);
con.setDoOutput(true);
String token = data.getBlackBoardSession();
// BB7 contains '@@'
final int expectedTokenLength = PASS_LENGTH + (token.startsWith("@@") ? 2 : 0);
if( token.length() == expectedTokenLength )
{
con.setRequestProperty("Cookie", "session_id=" /* @@" */+ token + ";");
}
// Open output stream and send username and password
PrintWriter conout = new PrintWriter(con.getOutputStream());
StringBuilder out = new StringBuilder();
out.append("method=" + name + "&");
if( parameters != null )
{
for( NameValue pair : parameters )
{
out.append(pair.getValue() + "=" + encode(pair.getName()) + "&");
}
}
conout.print(out.toString());
conout.close();
InputStream in = con.getInputStream();
PropBagEx xml = parseInputStream(in);
String cookie = con.getHeaderField("Set-Cookie");
if( cookie == null )
{
Map<String, List<String>> headerFields = con.getHeaderFields();
if( headerFields != null && !Check.isEmpty(headerFields.get("Set-Cookie")) )
{
cookie = headerFields.get("Set-Cookie").get(0);
}
}
xml.setNode("cookie", cookie);
in.close();
int buildingBlockDuration = xml.getIntNode("@invocationDuration", -1);
int thisMethodDuration = (int) ((System.currentTimeMillis() - startTime) / 1000);
StringBuilder sb = new StringBuilder("URL request from EQUELLA to Blackboard took ");
sb.append(thisMethodDuration);
sb.append(" second(s), where ");
sb.append(buildingBlockDuration);
sb.append(" second(s) where spent in the Building Block");
LOGGER.info(sb.toString());
return xml;
}