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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • COM组件原理_Com组件

    COM组件原理_Com组件在COM中,接口就是一个象类,每个接口有一个接口ID(uuid)。一个COM组件通常是连续继承下来的类,比如IUNknow->IDispath->IXX->CXX。这就形成了一个COM组件,当然组件一般是一个钻石继承的样子,这里为了简化原理把他们当成一个串形继承下来。每个COM组件都有一个CLSID(uuid),这个CLSID是注册的时候写进注册表的。这样就可以通过查询注册表中的CLSID

    2025年5月31日
    2
  • 制作动态头像_取网名独一无二的

    制作动态头像_取网名独一无二的制作一个炫酷的svg动态头像,闪瞎技术人的双眼吧

    2022年8月16日
    8
  • 【Android】Android游戏编程之从零开始[通俗易懂]

    【Android】Android游戏编程之从零开始[通俗易懂]《Android游戏编程之从零开始》主要系统地讲解了Android游戏开发,从最基础部分开始,让零基础的Android初学者也能快速学习和掌握Android游戏开发。《Android游戏编程之从零开始》一共8章,内容包括Android平台介绍与环境搭建、Hello,Android!项目剖析、游戏开发中常用的系统组件、游戏开发基础、游戏开发实战、游戏开发提高篇、Box2d物理引擎、物…

    2022年5月27日
    207
  • vue常见错误:Invalid prop: type check failed for prop “data“. Expected Array, got Object

    vue常见错误:Invalid prop: type check failed for prop “data“. Expected Array, got Object错误截图错误分析这个错误的意思是说:无效的命名数据:“数据”类型检查失败。期望数组,得到对象,那么我们这个时候很明白了,是类型不对,但是是哪一行的呢?打开错误信息下面的详情,这个时候找到后缀是自己页面的.vue文件,看看是哪一行,就知道问题在哪了!下面的是我的:warn @ vue.esm.js?efeb:610assertProp @ vue.esm.js?efeb:1691vali…

    2022年6月11日
    605
  • mysql修改表名

    mysql修改表名ALTER TABLE table_nameRENAMETOnew_table_name

    2022年6月1日
    25
  • android studio不能输入中文_Android模拟器

    android studio不能输入中文_Android模拟器很多Android项目的运行都需要用到中文输入法,在一年前的AndroidStudio需要导入输入法apk安装,现在新版的AndroidStudio免去了这个麻烦,下面就教大家如何设置谷歌拼音输入法。

    2022年8月30日
    2

发表回复

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

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