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


Java HttpURLConnection.setDoInput方法代码示例

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


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

示例1: openConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Opens an {@link HttpURLConnection} with parameters.
 * @param url
 * @return an open connection
 * @throws IOException
 */
private HttpURLConnection openConnection(URL url, Request<?> request) throws IOException {
    HttpURLConnection connection = createConnection(url);

    int timeoutMs = request.getTimeoutMs();
    connection.setConnectTimeout(timeoutMs);
    connection.setReadTimeout(timeoutMs);
    connection.setUseCaches(false);
    connection.setDoInput(true);

    // use caller-provided custom SslSocketFactory, if any, for HTTPS
    if ("https".equals(url.getProtocol()) && mSslSocketFactory != null) {
        ((HttpsURLConnection)connection).setSSLSocketFactory(mSslSocketFactory);
    }

    return connection;
}
 
开发者ID:HanyeeWang,项目名称:GeekZone,代码行数:23,代码来源:HurlStack.java

示例2: getConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static HttpURLConnection getConnection(URL url, String method, String contextType, HttpRequestEntity requestEntity)
        throws IOException {
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod(method);
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setRequestProperty("Accept", "*/*");
    conn.setRequestProperty("Content-Type", contextType);
    conn.setConnectTimeout(requestEntity.getConnectTimeout());
    conn.setReadTimeout(requestEntity.getReadTimeout());
    if (!requestEntity.getHeaders().isEmpty()) {
        for (Map.Entry<String, String> entry : requestEntity.getHeaders().entrySet()) {
            conn.setRequestProperty(entry.getKey(), entry.getValue());
        }
    }
    if (requestEntity.getBasicAuth() != null) {
        conn.setRequestProperty("Authorization", requestEntity.getBasicAuth().getEncodeBasicAuth());
    }
    return conn;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:21,代码来源:HttpUtils.java

示例3: getbitmap

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public static Bitmap getbitmap(String str) {
    f.a("AsynLoadImg", "getbitmap:" + str);
    try {
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
        httpURLConnection.setDoInput(true);
        httpURLConnection.connect();
        InputStream inputStream = httpURLConnection.getInputStream();
        Bitmap decodeStream = BitmapFactory.decodeStream(inputStream);
        inputStream.close();
        f.a("AsynLoadImg", "image download finished." + str);
        return decodeStream;
    } catch (IOException e) {
        e.printStackTrace();
        f.a("AsynLoadImg", "getbitmap bmp fail---");
        return null;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:18,代码来源:AsynLoadImg.java

示例4: download

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public void download(String uri, OutputStream destination)
		throws URISyntaxException, IOException {

	URL url = new URL(uri);
	HttpURLConnection conn = (HttpURLConnection) url.openConnection();
	conn.setDoInput (true);
	conn.setConnectTimeout(0);
	conn.setReadTimeout(0);
	conn.setRequestMethod("GET");

	conn.connect();
	InputStream input = conn.getInputStream();
	try{
		copy(input, destination);
	} finally {
		input.close();
	}
}
 
开发者ID:Microsoft,项目名称:healthvault-java-sdk,代码行数:19,代码来源:HttpStreamer.java

示例5: 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

示例6: MultipartUtility

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * This constructor initializes a new HTTP POST request with content type is
 * set to multipart/form-data
 * 
 * @param requestURL
 * @param charset
 * @throws IOException
 */
public MultipartUtility(String requestURL, String charset, long groupId, String authStringEnc) throws IOException {
	this.charset = charset;

	// creates a unique boundary based on time stamp
	boundary = "===" + System.currentTimeMillis() + "===";

	URL url = new URL(requestURL);
	httpConn = (HttpURLConnection) url.openConnection();
	httpConn.setUseCaches(false);
	httpConn.setDoOutput(true); // indicates POST method
	httpConn.setDoInput(true);
	httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
	httpConn.setRequestProperty("User-Agent", "OpenCPS-Agent");

	httpConn.setRequestProperty("Authorization", "Basic " + authStringEnc);

	httpConn.setRequestMethod(HttpMethods.POST);
	httpConn.setDoInput(true);
	httpConn.setDoOutput(true);
	httpConn.setRequestProperty("Accept", "application/json");
	httpConn.setRequestProperty("groupId", String.valueOf(groupId));

	outputStream = httpConn.getOutputStream();
	writer = new PrintWriter(new OutputStreamWriter(outputStream, charset), true);
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:34,代码来源:MultipartUtility.java

示例7: fastConfigureConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static HttpURLConnection fastConfigureConnection(HttpURLConnection http) {
	http.addRequestProperty("User-Agent",
			"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0 VkAuthLib/0.0.1 VkAccess/0.0.1");
	http.addRequestProperty("Accept-Language", "ru-ru,ru;q=0.5");
	http.setInstanceFollowRedirects(true);
	http.setDoInput(true);
	http.setDoOutput(true);
	return http;
}
 
开发者ID:Ivan-Alone,项目名称:VkAccess,代码行数:10,代码来源:VkAccess.java

示例8: openConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Opens an {@link HttpURLConnection} with parameters.
 *
 * @param request
 * @param listener
 * @return an open connection
 * @throws IOException
 */
private HttpURLConnection openConnection(WXRequest request, OnHttpListener listener) throws IOException {
  URL url = new URL(request.url);
  HttpURLConnection connection = createConnection(url);
  connection.setConnectTimeout(request.timeoutMs);
  connection.setReadTimeout(request.timeoutMs);
  connection.setUseCaches(false);
  connection.setDoInput(true);

  if (request.paramMap != null) {
    Set<String> keySets = request.paramMap.keySet();
    for (String key : keySets) {
      connection.addRequestProperty(key, request.paramMap.get(key));
    }
  }

  if ("POST".equals(request.method) || "PUT".equals(request.method) || "PATCH".equals(request.method)) {
    connection.setRequestMethod(request.method);
    if (request.body != null) {
      if (listener != null) {
        listener.onHttpUploadProgress(0);
      }
      connection.setDoOutput(true);
      DataOutputStream out = new DataOutputStream(connection.getOutputStream());
      //TODO big stream will cause OOM; Progress callback is meaningless
      out.write(request.body.getBytes());
      out.close();
      if (listener != null) {
        listener.onHttpUploadProgress(100);
      }
    }
  } else if (!TextUtils.isEmpty(request.method)) {
    connection.setRequestMethod(request.method);
  } else {
    connection.setRequestMethod("GET");
  }

  return connection;
}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:47,代码来源:DefaultWXHttpAdapter.java

示例9: downloadURL

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public static InputStream downloadURL(String link) throws IOException {
    URL url = new URL(link);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(10000);
    conn.setConnectTimeout(15000);
    conn.setRequestMethod("GET");
    conn.setDoInput(true);
    conn.connect();
    logInfo("downloadStatus: " + conn.getResponseCode());
    return conn.getInputStream();
}
 
开发者ID:DroidThug,项目名称:VulcanOTA,代码行数:12,代码来源:OTAUtils.java

示例10: post

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Post请求
 * 
 * @param url
 * @param params
 * @param https
 * @return
 * @throws IOException
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 * @throws KeyManagementException
 */
public static String post(String url, String body, boolean https) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
	// 创建链接
	URL u = new URL(url);
    HttpURLConnection http = (HttpURLConnection) u.openConnection();
    // 连接超时
    http.setConnectTimeout(10000);
    http.setReadTimeout(10000);
    http.setRequestMethod("POST");
    http.setRequestProperty("Content-Type","application/json");
    if(https) {
        SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
        sslContext.init(null, new TrustManager[]{new MyX509TrustManager()}, new SecureRandom());
        SSLSocketFactory ssf = sslContext.getSocketFactory();
        ((HttpsURLConnection)http).setSSLSocketFactory(ssf);
    }
    http.setDoOutput(true);
    http.setDoInput(true);
    http.connect();
    // 写入参数
    try (OutputStream out = http.getOutputStream()) {
     out.write(body.getBytes(DEFAULT_CHARSET));
     out.flush();
    }
    // 获取返回
    StringBuilder sb = new StringBuilder();
    try (InputStream is = http.getInputStream()) {
    	try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, DEFAULT_CHARSET))) {
    		String str = null;
    		while((str = reader.readLine()) != null) {
    			sb.append(str);str = null;
    		}
    	}
    }
    // 关闭链接
    if (http != null) {
        http.disconnect();
    }
    return sb.toString();
}
 
开发者ID:DNAProject,项目名称:DNASDKJava,代码行数:52,代码来源:RestHttp.java

示例11: openConnection

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private HttpURLConnection openConnection(URL url, Request<?> request) throws IOException {
    HttpURLConnection connection = createConnection(url);

    int timeoutMs = request.getTimeoutMs();
    connection.setConnectTimeout(timeoutMs);
    connection.setReadTimeout(timeoutMs);
    connection.setUseCaches(false);
    connection.setDoInput(true);

    return connection;
}
 
开发者ID:DLKanth,项目名称:Stetho-Volley,代码行数:12,代码来源:StethoVolleyStack.java

示例12: getMimeType

import java.net.HttpURLConnection; //导入方法依赖的package包/类
public String getMimeType(Uri uri) {
    switch (getUriType(uri)) {
        case URI_TYPE_FILE:
        case URI_TYPE_ASSET:
            return getMimeTypeFromPath(uri.getPath());
        case URI_TYPE_CONTENT:
        case URI_TYPE_RESOURCE:
            return contentResolver.getType(uri);
        case URI_TYPE_DATA: {
            return getDataUriMimeType(uri);
        }
        case URI_TYPE_HTTP:
        case URI_TYPE_HTTPS: {
            try {
                HttpURLConnection conn = (HttpURLConnection)new URL(uri.toString()).openConnection();
                conn.setDoInput(false);
                conn.setRequestMethod("HEAD");
                String mimeType = conn.getHeaderField("Content-Type");
                if (mimeType != null) {
                    mimeType = mimeType.split(";")[0];
                }
                return mimeType;
            } catch (IOException e) {
            }
        }
    }
    
    return null;
}
 
开发者ID:jie-meng,项目名称:DinningShare,代码行数:30,代码来源:CordovaResourceApi.java

示例13: getTNPImpl

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static String getTNPImpl( String userid, String password, String tpf, int count )
		throws IOException
	{
/*
		String domain = "login.passport.com";
		if( userid.endsWith("@hotmail.com") )
			domain = "loginnet.passport.com";
		else
		if( userid.endsWith("@msn.com") )
			domain = "msnialogin.passport.com";
*/
		String domain = "loginnet.passport.com";

		URL url0 = new URL(
			"https://" + domain + "/login2.srf");
		
		HttpURLConnection con0 = (HttpURLConnection)url0.openConnection();
		con0.setRequestMethod( "GET" );
		con0.setUseCaches( false );
		con0.setDoInput( true );

		con0.setRequestProperty( "Host", domain );
		String author = 
			"Passport1.4 OrgVerb=GET,OrgURL=http://messenger.msn.com," + 
			"sign-in=" + URLEncoder.encode(userid, "EUC-KR") + ",pwd=" + 
			password + "," + tpf;
		con0.setRequestProperty( "Authorization", author );

		String ret = getContent( con0.getInputStream(), con0.getContentLength() );		
		con0.disconnect();

		String auth = con0.getHeaderField("Authentication-Info");
		if( auth==null )
			return "t=0&p=0";

		String da_status = getValueFromKey(auth, "da-status"); // success, failed, redir
		String fromPP = getValueFromKey(auth, "from-PP");
		return fromPP;
	}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:40,代码来源:TWN.java

示例14: createRequest

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private static <T extends BaseResponse> HttpURLConnection createRequest(BaseRequest<T> request) throws Exception {

        String api = request.getApiUrl();

        if (request.getRequestMethod() == HttpMethod.GET && !request.getQueryString().isEmpty()) {
            URI uri = new URI(request.getApiUrl());
            if (!uri.getQuery().isEmpty()) {
                api = api + "&" + request.getQueryString();
            } else {
                api = api + "?" + request.getQueryString();
            }
        }

        URL url = new URL(api);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod(request.getRequestMethodHeader());
        connection.setUseCaches(false);
        connection.setInstanceFollowRedirects(true);
        connection.setRequestProperty("Content-Type", request.getContentTypeHeader());
        connection.setRequestProperty("User-Agent", request.getUserAgent());

        if (request.getHeaders() != null && request.getHeaders().size() > 0) {
            for (String key : request.getHeaders().keySet()) {
                connection.setRequestProperty(key, request.getHeaders().get(key));
            }
        }

        connection.connect();

        return connection;
    }
 
开发者ID:MalongTech,项目名称:productai-java-sdk,代码行数:34,代码来源:RequestHelper.java

示例15: get

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Get请求
 * 
 * @param url
 * @param https
 * @return
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 * @throws IOException
 * @throws KeyManagementException
 */
private static String get(String url /*,String body*/ ,boolean https) throws NoSuchAlgorithmException, NoSuchProviderException, IOException, KeyManagementException {
	// 创建链接
	URL u = new URL(url);
    HttpURLConnection http = (HttpURLConnection) u.openConnection();
    // 连接超时
    http.setConnectTimeout(50000);
    http.setReadTimeout(50000);
    http.setRequestMethod("GET");
    http.setRequestProperty("Content-Type","application/json");
    if(https) {
        SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
        sslContext.init(null, new TrustManager[]{new MyX509TrustManager()}, new SecureRandom());
        SSLSocketFactory ssf = sslContext.getSocketFactory();
        ((HttpsURLConnection)http).setSSLSocketFactory(ssf);
    }
    http.setDoOutput(true);
    http.setDoInput(true);
    http.connect();
    // 获取返回
    StringBuilder sb = new StringBuilder();
    try (InputStream is = http.getInputStream()) {
    	try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, DEFAULT_CHARSET))) {
    		String str = null;
    		while((str = reader.readLine()) != null) {
    			sb.append(str);str = null;
    		}
    	}
    }
    // 关闭链接
    if (http != null) {
        http.disconnect();
    }
    return sb.toString();
}
 
开发者ID:DNAProject,项目名称:DNASDKJava,代码行数:46,代码来源:RestHttp.java


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