当前位置: 首页>>代码示例>>Java>>正文


Java HttpURLConnection.setAllowUserInteraction方法代码示例

本文整理汇总了Java中java.net.HttpURLConnection.setAllowUserInteraction方法的典型用法代码示例。如果您正苦于以下问题:Java HttpURLConnection.setAllowUserInteraction方法的具体用法?Java HttpURLConnection.setAllowUserInteraction怎么用?Java HttpURLConnection.setAllowUserInteraction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.HttpURLConnection的用法示例。


在下文中一共展示了HttpURLConnection.setAllowUserInteraction方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: post

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Submits an HTTP POST request to the given URL.
 *
 * @param url the URL to receive the POST request
 * @return the reply
 * @throws IOException in case of failure
 */
public InputStream post(URL url) throws IOException {
  writeEnd();

  OutputStream out = null;
  try {
    final HttpURLConnection http = (HttpURLConnection) url.openConnection();

    http.setRequestMethod("POST");
    http.setDoInput(true);
    http.setDoOutput(true);
    http.setUseCaches(false);
    http.setAllowUserInteraction(false);

    http.setRequestProperty("Content-Type",
      "multipart/form-data; boundary=" + boundary);
    http.setRequestProperty("Content-Length", String.valueOf(bytes.size()));

    out = http.getOutputStream();
    bytes.writeTo(out);
    out.close();

    return http.getInputStream();
  }
  finally {
    IOUtils.closeQuietly(out);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:35,代码来源:HTTPPostBuilder.java

示例2: notifyURLOnce

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Notify the URL just once. Use best effort.
 */
protected boolean notifyURLOnce() {
  boolean success = false;
  try {
    Log.info("Job end notification trying " + urlToNotify);
    HttpURLConnection conn =
      (HttpURLConnection) urlToNotify.openConnection(proxyToUse);
    conn.setConnectTimeout(timeout);
    conn.setReadTimeout(timeout);
    conn.setAllowUserInteraction(false);
    if(conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
      Log.warn("Job end notification to " + urlToNotify +" failed with code: "
      + conn.getResponseCode() + " and message \"" + conn.getResponseMessage()
      +"\"");
    }
    else {
      success = true;
      Log.info("Job end notification to " + urlToNotify + " succeeded");
    }
  } catch(IOException ioe) {
    Log.warn("Job end notification to " + urlToNotify + " failed", ioe);
  }
  return success;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:27,代码来源:JobEndNotifier.java

示例3: getHttpURLConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
static HttpURLConnection getHttpURLConnection(URL url, int timeout) throws IOException {

                HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();

                httpURLConnection.setConnectTimeout(40000);
                httpURLConnection.setReadTimeout(timeout);
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setDoInput(true);
                httpURLConnection.setUseCaches(false);
                httpURLConnection.setAllowUserInteraction(false);
                httpURLConnection.setRequestMethod("POST");

                // HttpURLConnection httpURLConnection = new MyHttpURLConnection(url);

                return httpURLConnection;
        }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:B6401598.java

示例4: main

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
  HttpURLConnection httpURLConnection = new HttpURLConnection(null) {

    @Override
    public void connect() throws IOException {
      // TODO Auto-generated method stub
      System.out.println("");
    }

    @Override
    public boolean usingProxy() {
      // TODO Auto-generated method stub
      return false;
    }

    @Override
    public void disconnect() {
      // TODO Auto-generated method stub

    }
  };
  httpURLConnection.connect();
  httpURLConnection.setDoOutput(true);
  httpURLConnection.setAllowUserInteraction(false);
}
 
开发者ID:themaplelab,项目名称:ideal,代码行数:26,代码来源:URLConnTarget1.java

示例5: main

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public static void main(String... args) throws IOException {
  HttpURLConnection httpURLConnection = new HttpURLConnection(null) {

    @Override
    public void connect() throws IOException {
      // TODO Auto-generated method stub
      System.out.println("");
    }

    @Override
    public boolean usingProxy() {
      // TODO Auto-generated method stub
      return false;
    }

    @Override
    public void disconnect() {
      // TODO Auto-generated method stub

    }
  };
  httpURLConnection.setDoOutput(true);
  httpURLConnection.setAllowUserInteraction(false);

  httpURLConnection.connect();
}
 
开发者ID:themaplelab,项目名称:ideal,代码行数:27,代码来源:URLConnTarget2.java

示例6: prepRequest

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private HttpURLConnection prepRequest(String url, Iterable<Header> headers) throws IOException {
    URL urlObject = new URL(url);
    HttpURLConnection conn = (HttpURLConnection) urlObject.openConnection(config.getProxy());

    conn.setConnectTimeout((int) config.getConnectTimeoutMillis());
    conn.setReadTimeout((int) config.getReadTimeoutMillis());
    conn.setUseCaches(false);
    conn.setAllowUserInteraction(false);

    // Some JREs (like the one provided by Google AppEngine) will return HttpURLConnection
    // instead of HttpsURLConnection. So we have to check here.
    if (conn instanceof HttpsURLConnection) {
        HttpsURLConnection httpsConn = (HttpsURLConnection) conn;
        httpsConn.setSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault());
        // SSLConfig.apply((HttpsURLConnection) conn);
        configure(conn);
    } else {
        logCertificatePinningWarning();
    }

    configure(conn);

    for (Header header : headers) {
        conn.addRequestProperty(header.getKey(), header.getValue());
    }

    return conn;
}
 
开发者ID:yifangyun,项目名称:fangcloud-java-sdk,代码行数:29,代码来源:StandardHttpRequestor.java

示例7: getResponse

import java.net.HttpURLConnection; //导入方法依赖的package包/类
@Override
public ResponseScriptType getResponse(boolean isGET)
{
	try
	{
		final String data = getFormData();

		String extra = "";
		if( isGET && !Check.isEmpty(data) )
		{
			String qs = url.getQuery();
			if( Check.isEmpty(qs) )
			{
				extra += "?" + data;
			}
			else
			{
				extra += "?" + qs + "&" + data;
			}
		}
		final String urlString = url.toString() + extra;

		final URL finalUrl = new URL(urlString);
		final HttpURLConnection conn = (HttpURLConnection) finalUrl.openConnection();

		conn.setRequestMethod(isGET ? "GET" : "POST");
		conn.setAllowUserInteraction(false);
		conn.setInstanceFollowRedirects(true);

		conn.setDoOutput(true);
		conn.setDoInput(true);

		// Send data
		conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
		conn.setRequestProperty("Accept", "*/*");

		if( !isGET )
		{
			try( Writer wr = new OutputStreamWriter(conn.getOutputStream()) )
			{
				if( !isGET )
				{
					wr.write(data);
				}
				wr.flush();
			}
		}

		// Get the response
		final String contentType = conn.getContentType();

		try( InputStream is = conn.getInputStream() )
		{
			if( contentType == null || contentType.startsWith("text/") )
			{
				Reader rd = new InputStreamReader(is);
				StringWriter sw = new StringWriter();
				CharStreams.copy(rd, sw);
				return new ResponseScriptTypeImpl(sw.toString(), conn.getResponseCode(), contentType);
			}
			else
			{
				ByteArrayOutputStream os = new ByteArrayOutputStream();
				ByteStreams.copy(is, os);
				return new ResponseScriptTypeImpl(os.toByteArray(), conn.getResponseCode(), contentType);
			}
		}
	}
	catch( IOException e )
	{
		return new ResponseScriptTypeImpl("ERROR: " + e.getMessage(), 400, "text/plain");
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:74,代码来源:UtilsScriptWrapper.java

示例8: shouldUpload

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private boolean shouldUpload ( final MavenReference ref ) throws Exception
{
    System.out.format ( "baseline validation: %s%n", ref );

    final String group = ref.getGroupId ().replace ( '.', '/' );

    final String uri = String.format ( "http://central.maven.org/maven2/%s/%s/%s/%s", group, ref.getArtifactId (), ref.getVersion (), ref.toFileName () );

    final URL url = new URL ( uri );
    final HttpURLConnection con = openConnection ( url );
    con.setAllowUserInteraction ( false );

    con.setConnectTimeout ( getInteger ( "maven.central.connectTimeout", getInteger ( "maven.central.timeout", 0 ) ) );
    con.setReadTimeout ( getInteger ( "maven.central.readTimeout", getInteger ( "maven.central.timeout", 0 ) ) );

    con.connect ();
    try
    {
        final int rc = con.getResponseCode ();
        System.out.format ( "\t%s -> %s%n", url, rc );
        if ( rc == 404 )
        {
            // file is not there ... upload
            return true;
        }

        final Path tmp = Files.createTempFile ( null, ".jar" );
        try
        {
            try ( final InputStream in = con.getInputStream ();
                  final OutputStream out = Files.newOutputStream ( tmp ) )
            {
                ByteStreams.copy ( in, out );
            }

            performBaselineCheck ( makeJarFile ( makeVersionBase ( ref ), ref ), tmp );
        }
        finally
        {
            Files.deleteIfExists ( tmp );
        }
    }
    finally
    {
        con.disconnect ();
    }

    // don't upload, since the bundle is already there
    return false;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:51,代码来源:Processor.java

示例9: connect

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public Response connect() throws IOException {
	boolean isGet = false;
	String queryString = null;
	URI uri = URI.create(mUrl);

	if ("GET".equalsIgnoreCase(mMethod)) {
		isGet = true;
	} else if ("POST".equalsIgnoreCase(mMethod)) {
		isGet = false;
		mUrl = uri.getScheme() + "//" + uri.getHost() + uri.getPath();
		queryString = uri.getQuery();
	}

	mURLConnection = new URL(mUrl).openConnection();
	HttpURLConnection connection = (HttpURLConnection) mURLConnection;

	// 處理request header---begin---
	setUpRequestProperty(connection);
	// 處理request header---end---

	if (mReadTimeout != null) {
		connection.setReadTimeout(mReadTimeout.intValue());
	}

	if (mConnectTimeout != null) {
		connection.setConnectTimeout(mConnectTimeout.intValue());
	}

	connection.setDoInput(true);
	connection.setRequestMethod(mMethod.toUpperCase());

	if (!isGet) {
		connection.setDoOutput(true);
	}

	connection.setUseCaches(false);
	connection.setAllowUserInteraction(true);

	if (mIsRedirect != null) {
		connection.setInstanceFollowRedirects(mIsRedirect);
	}

	if (!isGet && queryString != null && !queryString.isEmpty()) {
		BufferedOutputStream dos = new BufferedOutputStream(
				new DataOutputStream(connection.getOutputStream()));
		dos.write(queryString.getBytes(mWriteCharset));
		dos.flush();
		dos.close();
	}

	try {
		return createResponse(connection, true);
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		if (connection.getInputStream() != null) {
			connection.getInputStream().close();
		}
	}
	return null;
}
 
开发者ID:RayTW,项目名称:8ComicSDK-JAVA,代码行数:62,代码来源:EasyHttp.java


注:本文中的java.net.HttpURLConnection.setAllowUserInteraction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。