當前位置: 首頁>>代碼示例>>Java>>正文


Java URLConnection.setDoInput方法代碼示例

本文整理匯總了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;
}
 
開發者ID:yi-jun,項目名稱:aaden-pay,代碼行數:17,代碼來源:AllinpayXmlTools.java

示例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;
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:24,代碼來源:CollectionImporter.java

示例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();
}

}
 
開發者ID:pratikdimble,項目名稱:Servlet_Applet_Communication,代碼行數:21,代碼來源:LoginApplet.java

示例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;
}
 
開發者ID:mqsysadmin,項目名稱:dpdirect,代碼行數:25,代碼來源:PostXML.java

示例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();
}
 
開發者ID:upcyiban,項目名稱:Integrate,代碼行數:23,代碼來源:QueryService.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:ReporterResultTopComponent.java

示例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 );
    }

}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:16,代碼來源:YahooStockQuoteService.java

示例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;
}
 
開發者ID:SentinelDataHub,項目名稱:dhus-core,代碼行數:32,代碼來源:HttpNode.java

示例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;
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:38,代碼來源:CollectionImporter.java

示例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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:MessageBodyWebRequest.java

示例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();
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:14,代碼來源:MessageBodyWebRequest.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:37,代碼來源:XMLEntityManager.java

示例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;
}
 
開發者ID:wooui,項目名稱:springboot-training,代碼行數:36,代碼來源:HttpUtil.java

示例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();
    }
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:57,代碼來源:ResourceServlet.java

示例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;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:71,代碼來源:Blackboard.java


注:本文中的java.net.URLConnection.setDoInput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。