request获取请求参数_request.getquerystring()

request获取请求参数_request.getquerystring()IachievethePOSTrequestinAndroidanduploadapicturetoservicesuccessful.IdidnotusethesetRequestPropertyfunction;ButIwanttoknowwhattheeffectaboutthisfunctionis.Thisistheco…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

request获取请求参数_request.getquerystring()

I achieve the POST request in Android and upload a picture to service successful.

I did not use the setRequestProperty function; But I want to know what the effect about this function is.

This is the code:

URL url = new URL(“http://192.168.191.104:8080/myapp/servlet/MyServlet”);

HttpURLConnection connection = ((HttpURLConnection) url

.openConnection());

connection.setDoInput(true);

connection.setDoOutput(true);

connection.setUseCaches(false);

connection.setRequestMethod(“POST”);

connection.connect();

OutputStream out = connection.getOutputStream();

int len;

byte[] buffer = new byte[1024];

// 读取文件

FileInputStream fileInputStream = new FileInputStream(Environment

.getExternalStorageDirectory().getAbsolutePath() + “/123.jpg”);

while ((len = fileInputStream.read(buffer, 0, 1024)) != -1) {

out.write(buffer);

}

out.flush();

out.close();

fileInputStream.close();

InputStream input = connection.getInputStream();

while ((len = input.read(buffer)) != -1) {

Log.i(“tag”, “data:” + new String(buffer, 0, len));

}

input.close();

connection.disconnect();

Could anyone explain the effect of setRequestProperty function in HttpURLConnection?

解决方案

Mainly setRequestProperty is used to set below things as per the requirement

connection.setRequestProperty(“Connection”, “Keep-Alive”);

connection.setRequestProperty(“Content-Type”, “multipart/form-data;boundary=”+boundary);

or

Connection.setRequestProperty(“Content-Type”, “text/plain; charset=utf-8”);

Sometimes it become necessary that you have to specify Content-type for the connection.

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

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

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


相关推荐

  • 太厉害了,终于有人能把TCPIP协议讲的明明白白了!

    太厉害了,终于有人能把TCPIP协议讲的明明白白了!太厉害了,终于有人能把TCP/IP协议讲的明明白白了!从字面意义上讲,有人可能会认为TCP/IP是指TCP和IP两种协议。实际生活当中有时也确实就是指这两种协议。然而在很多情况下,它只是利用IP进行通信时所必须用到的协议群的统称。具体来说,IP或ICMP、TCP或UDP、TELNET或FTP、以及HTTP等都属于TCP/IP协议。一图看完本文一、计算机…

    2022年6月18日
    61
  • 手机连接服务器工具Termius使用<IOS版本>

    手机连接服务器工具Termius使用<IOS版本>

    2021年5月31日
    126
  • 获取当前jar包路径_java获取jar文件

    获取当前jar包路径_java获取jar文件一、获取可执行jar包所在目录(1)方法一:使用System.getProperty(“java.class.path”)获取classpath的路径,若没有其他依赖,在cmd下运行该可执行jar包,则该值即为该jar包的绝对路径。代码如下:/***方法一:获取当前可执行jar包所在目录*/StringfilePath=System.getProperty(“java.class.

    2022年9月27日
    3
  • postman安装包怎么安装_数据库安装教程

    postman安装包怎么安装_数据库安装教程一、Postman背景介绍用户在开发或者调试网络程序或者是网页B/S模式的程序的时候是需要一些方法来跟踪网页请求的,用户可以使用一些网络的监视工具比如著名的Firebug等网页调试工具。今天给大家介绍的这款网页调试工具不仅可以调试简单的css、html、脚本等简单的网页基本信息,它还可以发送几乎所有类型的HTTP请求!Postman在发送网络HTTP请求方面可以说是Chrome插件类产品中的代表产品之一。二、Postman的操作环境postman适用于不同的操作系统,PostmanMac、Windo

    2026年1月15日
    3
  • springboot的启动流程及原理_精馏的原理及流程

    springboot的启动流程及原理_精馏的原理及流程1.springboot的启动类入口@SpringBootApplication@ComponentScan(basePackages={“cn”})publicclassSpringBootDemo{publicstaticvoidmain(String[]args){SpringApplication.run(SpringBootDemo.class);}}可以看出,Annotation定义(@SpringBootApplicati

    2022年8月21日
    8
  • Java设计模式之结构型:桥接模式

    Java设计模式之结构型:桥接模式

    2021年10月5日
    44

发表回复

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

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