當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。