html获取表单提交数据_提交表单的两种方法

html获取表单提交数据_提交表单的两种方法转载于:https://blog.csdn.net/yongwoozzang/article/details/83029128HttpURLConnectionx-www-form-urlencodedpublicstaticStringPost(StringhttpUrl,Stringdata){ PrintWriterout=null; InputStr…


Jetbrains全系列IDE稳定放心使用

转载于:https://blog.csdn.net/yongwoozzang/article/details/83029128

HttpURLConnection x-www-form-urlencoded

 
public static String Post(String httpUrl, String data) {
	PrintWriter out = null;
	InputStream readStream = null;
	String output = data;
	String result = "";
 
	try {
		output = "value1=" + URLEncoder.encode(output, "UTF-8");
	} catch (UnsupportedEncodingException e1) {
		e1.printStackTrace();
	}
 
	try {
		URL postUrl = new URL(httpUrl);
		HttpURLConnection conn = (HttpURLConnection) postUrl.openConnection();
		conn.setConnectTimeout(5000);
		conn.setDoOutput(true);
		conn.setDoInput(true);
		conn.setUseCaches(false);
		conn.setRequestMethod("POST");
		conn.setRequestProperty("accept", "*/*");
		conn.setRequestProperty("Connection", "Keep-Alive");
		conn.setRequestProperty("Charset", "UTF-8");
		conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");//关键代码 application/x-www-form-urlencoded
		out = new PrintWriter(conn.getOutputStream());
		out.print(output);
		out.flush();
		out.close();
		if (conn.getResponseCode() != 200) {
			throw new Exception("请求url失败");
		}
		readStream = conn.getInputStream();
		result = ll.InputStreamToString(readStream);
 
		return result;
	} catch (Exception e) {
		e.printStackTrace();
		result = ll.InputStreamToString(readStream);
		return result;
	} finally {
		if (out != null) {
			out.close();
		}
		if (readStream != null) {
			try {
				readStream.close();
			} catch (IOException e) {
				return null;
			}
		}
	}
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/185280.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • stringtokenizer是什么意思_string copy

    stringtokenizer是什么意思_string copyStringTokenizer可以将一个字符串分解为一个一个的单词或者标记。常用方法如下:methodcontentintcountTokens()返回nextToken方法被调用的次数。booleanhasMoreTokens()返回是否还有分隔符。booleanhasMoreElements()返回是否还有分隔符。StringnextTo…

    2022年9月19日
  • Java笔试题大全(附带答案)「建议收藏」

    Java笔试题大全(附带答案)「建议收藏」一、单选题1.下列哪一种叙述是正确的(D)A.abstract修饰符可修饰字段、方法和类B.抽象方法的body部分必须用一对大括号{}包住C.声明抽象方法,大括号可有可无D.声明抽象方法不可写出大括号2.如下代码publicclassTest{publicintaMethod(){staticinti=0;i++;returni;}…

    2022年7月7日
  • openstack单元測试用组件一览

    openstack单元測试用组件一览

    2021年12月1日
  • python语音信号处理(一)「建议收藏」

    python语音信号处理(一)「建议收藏」1.引言python已经支持WAV格式的书写,而实时的声音输入输出需要安装pyAudio。最后我们还将使用pyMedia进行Mp3的解码和播放。音频信号是模拟信号,我们需要将其保存为数字信号,才能对语音进行算法操作,WAV是Microsoft开发的一种声音文件格式,通常被用来保存未压缩的声音数据。语音信号有四个重要的参数:声道数、采样频率、量化位数(位深)和比特率声道数:可以是单声道、双声道…采样频率(Samplerate):每秒内对声音信号采样样本的总数目,44100Hz采样频率意味着

    2022年5月24日
  • 彩色图和深度图转点云

    彩色图和深度图转点云环境:windows10、VS2013、opencv2.49、openNi、PCL1.8opencv环境搭建参考https://www.cnblogs.com/cuteshongshong/p/4057193.htmlhttps://blog.csdn.net/u013105549/article/details/50493069PCL1.8+openNi搭建参考https://blog.cs…

    2022年4月25日
  • chorme 显示“请在微信客户端打开链接”

    chorme 显示“请在微信客户端打开链接”chorme显示“请在微信客户端打开链接”

    2022年5月29日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号