博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
http delete 方法传参数遇到java.net.ProtocolException: DELETE does not support writing的问题...
阅读量:6840 次
发布时间:2019-06-26

本文共 1417 字,大约阅读时间需要 4 分钟。

最近在测试通过http delete method传参数调用服务端方法,遇到了java.net.ProtocolException: DELETE does not support writing

 

try {				url = new URL(path);				HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();				httpCon.setDoOutput(true);				httpCon.setRequestMethod(method);				OutputStreamWriter out = new OutputStreamWriter(						httpCon.getOutputStream());				out.write(new Gson().toJson(params));				out.close();							String urlStringsss = convertStreamToString(httpCon.getInputStream());				InfoPrinter.printLog(convertStreamToString(httpCon.getInputStream()));			} catch (MalformedURLException e) {				// TODO Auto-generated catch block				e.printStackTrace();			} catch (IOException e) {				// TODO Auto-generated catch block				e.printStackTrace();			}

  执行时捕捉到

java.net.ProtocolException: DELETE does not support writing

后来在万能的google帮助下,最终在stackoverflow上找到了答案,先来看国外的一位Coder怎么说

I do not believe that HTTP DELETE takes input - I believe it acts like a GET variant.The implementation provided by HTTP Client seems to support this conjecture as well.If you are looking to provide a delete with a body, you /might/ want to consider using a POST to a location that accepts a body.But in answer to your question, no, delete does not accept a body. You can add query parameters but not a body.

HTTP DELETE 不支持通过output来write参数,只能像GET方法一样通过url paramter来传递参数,否则会报标题上遇到的错误。

转载于:https://www.cnblogs.com/fukai316/p/3862496.html

你可能感兴趣的文章
BIND9源码分析之 多个view的情况下如何做dynamic update
查看>>
openssl 证书操作
查看>>
精简版StringBuilder,提速字符串拼接
查看>>
位运算
查看>>
HDU 4708 Rotation Lock Puzzle(模拟)
查看>>
Chapter 6 -- Caches
查看>>
wpf/Silverlight/wp中如何绑定模板中的属性
查看>>
Netty Associated -- Channel
查看>>
vim 配置
查看>>
数据结构与算法实验题6.1 s_sin’s bonus byFZuer
查看>>
C#点点滴滴:枚举enum
查看>>
白盒密码入门
查看>>
在数据仓库建模时,应该使用哪种数据类型的度量值
查看>>
Gradle学习系列之九——自定义Task类型
查看>>
教你如何自定义组件
查看>>
第一部分:开发前的准备-第一章 什么是Andorid
查看>>
硬件升级win8.1重新安装系统
查看>>
servlet awt随机图片验证码
查看>>
ios开发怎样才能做到代码和界面彻底分离,方便换肤?
查看>>
Orchard Express Oracle v1.7.2 发布
查看>>