使用Okhttp执行put空的RequestBody
来源:互联网 发布:淘宝绽放茉莉恶心 编辑:程序博客网 时间:2024/06/15 10:21
由于特殊原因,客户端需要请求一个put请求,但是什么参数都不需要,具体的参数已经在url里面了,但是Okhttp必须要在Put是传递一个RequestBody参数
源码:
public Builder put(RequestBody body) { return method("PUT", body); }...public Builder method(String method, RequestBody body) { if (method == null) throw new NullPointerException("method == null"); if (method.length() == 0) throw new IllegalArgumentException("method.length() == 0"); if (body != null && !HttpMethod.permitsRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must not have a request body."); } if (body == null && HttpMethod.requiresRequestBody(method)) { throw new IllegalArgumentException("method " + method + " must have a request body."); } this.method = method; this.body = body; return this; }
可以看到不传就回抛异常,对于这种情况可以如下处理:
RequestBody requestBody = RequestBody.create(null, new byte[]{});Request request = new Request.Builder() .url(url) .header("Content-Type",contentType) .put(requestBody) .build();
阅读全文
0 0
- 使用Okhttp执行put空的RequestBody
- android---okhttp怎么才能post一个空的requestbody
- Android必知必会-使用okhttp的PUT方式上传文件
- Spring RequestBody 的使用
- @RequestBody的使用
- spring中使用@RequestBody,对应的bean中属性名大写注入为空的解决方法
- spring中使用@RequestBody,对应的bean中属性名大写注入为空的解决方法
- 使用@RequestBody遇到的问题
- @RequestBody与@ResponseBody的使用
- @responseBody @@RequestBody注解的使用
- Okhttp post 发送空的body
- 在fragment中使用ButterKnife, 加Okhttp等异步网络库时的空指针异常
- @RequestBody使用
- 使用put方法接收客户端提交的put请求
- OkHttp的使用介绍
- OkHttp的简单使用
- OKHttp的简单使用
- android OkHttp的使用
- Android Retrofit请求服务器返回字符串(非JSON)
- ZOJ2975 伪数组压缩+组合数
- 大数据常见错误解决方案(转载)
- 冒泡排序
- ERROR Error when sending message to topic test_topic with key: null, value: 3 bytes……:部署Kafka时遇到两个问题
- 使用Okhttp执行put空的RequestBody
- java.lang.NoSuchFieldError: INSTANCE 解决方法
- java中指定编码操作文本文件
- 想要控制Linux GPIO初始状态的看过来
- CentOS7关闭防火墙
- 旗正规则引擎内存表出错的原因及解决方法分享
- Day12-40.return
- js接收thinkphp传递的参数
- RHEL环境搭建-NginxTomcatJavaDubboRabbitMQRedisNexusMySQL