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


Java URLConnection.setDoOutput方法代码示例

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


在下文中一共展示了URLConnection.setDoOutput方法的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: shareAndGetResponse

import java.net.URLConnection; //导入方法依赖的package包/类
private String shareAndGetResponse(String selection, int languageDropdownId) throws IOException {
    URL url = new URL("http://pastie.org/pastes");
    URLConnection conn = url.openConnection();
    conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    conn.setDoOutput(true);
    OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());

    String data = "paste[parser_id]=" + languageDropdownId +
            "&paste[authorization]=burger&paste[restricted]=1&paste[body]=" + URLEncoder.encode(selection, "UTF-8");
    writer.write(data);
    writer.flush();
    writer.close();

    StringBuffer answer = loadResponse(conn);
    return answer.toString();
}
 
开发者ID:phweda,项目名称:MFM,代码行数:17,代码来源:Pastie.java

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

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

示例5: getUrlAsString

import java.net.URLConnection; //导入方法依赖的package包/类
public static String getUrlAsString(String url) throws IOException {
  File file = new File(url);
  if (file.isFile()) {
    byte[] encoded = Files.readAllBytes(Paths.get(url));
    return new String(encoded, StandardCharsets.UTF_8);
  }

  URL urlObj = new URL(url);
  URLConnection con = urlObj.openConnection();

  con.setDoOutput(true);
  con.connect();

  BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

  StringBuilder response = new StringBuilder();
  String inputLine;

  String newLine = System.getProperty("line.separator");
  while ((inputLine = in.readLine()) != null) {
    response.append(inputLine + newLine);
  }

  in.close();

  return response.toString();
}
 
开发者ID:jomof,项目名称:cdep,代码行数:28,代码来源:WebUtils.java

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

示例7: privateApiQuery

import java.net.URLConnection; //导入方法依赖的package包/类
/**
 * Performs a raw private API query.
 * @param method the REST resource
 * @param postParam the JSON to send in the request body.
 * @return result JSON
 */
//Thanks to sampey from https://www.cryptopia.co.nz/Forum/Thread/262
private String privateApiQuery(String method, String postParam) {
    if (secretKey == null) {
        throw new CryptopiaClientException("Please set your secret key before attempting " +
                "to access any private API methods.");
    }
    if (key == null) {
        throw new CryptopiaClientException("Please set your key before attempting " +
                "to access any private API methods.");
    }
    BufferedReader in = null;
    try {
        final String urlMethod = String.format("%s/%s/%s", ROOT_URL, PRIVATE_PATH, method);
        final String nonce = String.valueOf(System.currentTimeMillis());
        final StringBuilder reqSignature = new StringBuilder();
        reqSignature
                .append(key)
                .append("POST")
                .append(URLEncoder.encode(urlMethod, StandardCharsets.UTF_8.toString()).toLowerCase())
                .append(nonce)
                .append(getMD5_B64(postParam));
        final StringBuilder auth = new StringBuilder();
        auth.append("amx ")
                .append(key)
                .append(":")
                .append(sha256_B64(reqSignature.toString()))
                .append(":")
                .append(nonce);
        final URLConnection con = new URL(urlMethod).openConnection();
        con.setDoOutput(true);
        final HttpsURLConnection httpsConn = (HttpsURLConnection) con;
        httpsConn.setRequestMethod("POST");
        httpsConn.setInstanceFollowRedirects(true);
        con.setRequestProperty("Authorization", auth.toString());
        con.setRequestProperty("Content-Type", "application/json");
        final DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(postParam);
        wr.flush();
        wr.close();
        in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuilder response = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        return response.toString();
    }catch (Exception e) {
        throw new CryptopiaClientException("An error occurred communicating with Cryptopia.", e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ignored) {}
        }
    }
}
 
开发者ID:dylanjsa,项目名称:cryptopia4j,代码行数:63,代码来源:CryptopiaClient.java

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

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

import java.net.URLConnection; //导入方法依赖的package包/类
public static final byte[] post(String url, String data, Map<String, String> headers) {
	try {
		URLConnection conn = new URL(url).openConnection();
		conn.setDoOutput(true);

		if (headers != null) {
			for (Map.Entry<String, String> entry : headers.entrySet()) {
				conn.setRequestProperty(entry.getKey(), entry.getValue());
			}
		}
		OutputStream os = conn.getOutputStream();
		OutputStreamWriter wr = new OutputStreamWriter(os);
		wr.write(data);
		wr.flush();
		wr.close();
		os.close();
		System.out.println("HTTP Response headers: " + conn.getHeaderFields());
		List<String> header = conn.getHeaderFields().get("Content-Disposition");
		if (header != null && header.size() > 0) {
			headers.put("Content-Disposition", header.get(0));
		}
		header = conn.getHeaderFields().get("Content-Type");
		if (header != null && header.size() > 0) {
			headers.put("Content-Type", header.get(0));
		}
		InputStream is = conn.getInputStream();
		byte[] result = IOUtils.toByteArray(is);
		is.close();
		return result;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:34,代码来源:HttpUtils.java

示例11: setConnectionParameters

import java.net.URLConnection; //导入方法依赖的package包/类
public void setConnectionParameters(URLConnection connection,
    HttpRequestMethod requestMethod) throws ProtocolException {
connection.setRequestProperty("User-Agent", USER_AGENT);
connection.setRequestProperty("Content-Type", JSON_MEDIA_TYPE);
connection.setRequestProperty("Accept", JSON_MEDIA_TYPE);
if (requestMethod.equals(HttpRequestMethod.POST)) {
    connection.setDoOutput(true);
}
   }
 
开发者ID:ahmed-ebaid,项目名称:invest-stash-rest,代码行数:10,代码来源:HttpRequests.java

示例12: doPlipPost

import java.net.URLConnection; //导入方法依赖的package包/类
private String doPlipPost() throws IOException {
    String boundary = Long.toHexString(System.currentTimeMillis());
    String crlf = "\r\n";

    String login = Base64.getEncoder().encodeToString(PLIP_REST_PROVIDER_CREDENTIALS.getBytes());
    URLConnection connection = new URL(plipUrl).openConnection();
    connection.setDoOutput(true);
    connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
    connection.setRequestProperty("Authorization", "Basic " + login);

    OutputStream output = connection.getOutputStream();
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, CHARSET), true);
    writer.append("--").append(boundary).append(crlf);
    writer.append("Content-Disposition: form-data; name=\"file\"; filename=\"").append(pdbFilePath.getFileName().toString()).append("\"").append(crlf);
    writer.append("Content-Type: text/plain; charset=" + CHARSET).append(crlf); // Text file itself must be saved in this charset!
    writer.append(crlf).flush();
    Files.copy(pdbFilePath, output);
    output.flush();
    writer.append(crlf).flush();
    writer.append("--").append(boundary).append("--").append(crlf).flush();

    int responseCode = ((HttpURLConnection) connection).getResponseCode();
    logger.info("PLIP REST service response code is " + responseCode);

    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String outputContent;
    StringBuilder response = new StringBuilder();

    while ((outputContent = in.readLine()) != null) {
        response.append(outputContent);
    }
    in.close();

    return response.toString();
}
 
开发者ID:enauz,项目名称:mmm,代码行数:36,代码来源:PlipPostRequest.java

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

示例14: read

import java.net.URLConnection; //导入方法依赖的package包/类
private boolean read() {
    try {
        final URLConnection conn = this.url.openConnection();
        conn.setConnectTimeout(5000);

        if (this.apiKey != null) {
            conn.addRequestProperty("X-API-Key", this.apiKey);
        }
        conn.addRequestProperty("User-Agent", "Updater (by Gravity)");

        conn.setDoOutput(true);

        final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        final String response = reader.readLine();

        final JSONArray array = (JSONArray) JSONValue.parse(response);

        if (array.size() == 0) {
            this.plugin.getLogger().warning("The updater could not find any files for the project id " + this.id);
            this.result = UpdateResult.FAIL_BADID;
            return false;
        }

        this.versionName = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TITLE_VALUE);
        this.versionLink = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.LINK_VALUE);
        this.versionType = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TYPE_VALUE);
        this.versionGameVersion = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.VERSION_VALUE);

        return true;
    } catch (final IOException e) {
        if (e.getMessage().contains("HTTP response code: 403")) {
            this.plugin.getLogger().warning("dev.bukkit.org rejected the API key provided in plugins/Updater/config.yml");
            this.plugin.getLogger().warning("Please double-check your configuration to ensure it is correct.");
            this.result = UpdateResult.FAIL_APIKEY;
        } else {
            this.plugin.getLogger().warning("The updater could not contact dev.bukkit.org for updating.");
            this.plugin.getLogger().warning("If you have not recently modified your configuration and this is the first time you are seeing this message, the site may be experiencing temporary downtime.");
            this.result = UpdateResult.FAIL_DBO;
        }
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:Borlea,项目名称:EchoPet,代码行数:44,代码来源:Updater.java

示例15: sendPost

import java.net.URLConnection; //导入方法依赖的package包/类
/**
 * 向指定 URL 发送POST方法的请求
 * 
 * @param url
 *            发送请求的 URL
 * @param param
 *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
 * @return 所代表远程资源的响应结果
 */
public static String sendPost(String url, String param) {
    PrintWriter out = null;
    BufferedReader in = null;
    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对象对应的输出流
        out = new PrintWriter(conn.getOutputStream());
        // 发送请求参数
        out.print(param);
        // flush输出流的缓冲
        out.flush();
        // 定义BufferedReader输入流来读取URL的响应
        in = new BufferedReader(
                new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = in.readLine()) != null) {
            result += line;
        }
    } catch (Exception e) {
        System.out.println("发送 POST 请求出现异常!"+e);
        e.printStackTrace();
    }
    //使用finally块来关闭输出流、输入流
    finally{
        try{
            if(out!=null){
                out.close();
            }
            if(in!=null){
                in.close();
            }
        }
        catch(IOException ex){
            ex.printStackTrace();
        }
    }
    return result;
}
 
开发者ID:cuiods,项目名称:WIFIProbe,代码行数:59,代码来源:HttpRequestUtil.java


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