根据官方的文档,这个接口需要post方法,进行请求 String postUrl = "https://api.weibo.com/oauth2/access_token?client_id=" + APPKEY + "&client_secret=" + APPSECRET + "&grant_type=authorization_code&redirect_uri=" + REDIRECT_URI + "&code=" + code; Request mRequest = new Request.Builder(...
因此,根据HTTP标准,GET请求通常不包含请求体(request body)。请求体一般用于POST、PUT等可能会修改服务器状态的方法中。OkHttp遵循这一标准,因此在OkHttp中,GET请求是不允许包含请求体的。 在OkHttp中正确使用GET方法进行网络请求的指导 在OkHttp中,使用GET方法进行网络请求非常简单。你可以通过构建一个Request对象,并...
Hi, i'm encountering same problem as with #745, but at this time with POST method. I don't really care what specs saying about whether POST must have a body or not, but I definitely know, that some server APIs don't expect any body at al...
But when I use expanders in my case all parameters put in the body of the request, but in my example, I use GET method and this is unacceptable to have body in GET method and that is why when I use OkHttp client I got the error "method GET must not have a request body.". To...
Builder() .url("http://example.com") .get() .build(); // Throws: java.lang.IllegalArgumentException: method GET must not have a request body. Request request = new Request.Builder() .url("http://example.com") .method("GET", requestBody) .build(); 是否有机会在 OkHttp 中构建...
POST请求 RequestBody--json数据提交 FormBody--表单数据提交 MultipartBody--文件上传 一、Get请求 一个最简单的使用okhttp进行网络请求的例子,get获取访问网页的内容,返回的即是这个网页的html,将内容显示出来 //主要代码 private void sendGetRuquestWithOkHttp() { ...
OKHttp的post提交 在Android应用中进行post提交通常用于向服务器提交数据或进行登录操作。下面是使用OKHttp进行post提交的代码示例: // 创建OKHttp客户端OkHttpClientclient=newOkHttpClient();// 创建POST请求体RequestBodyrequestBody=newFormBody.Builder().add("username","john").add("password","123456").build...
接着看Request的创建,也是使用建造者模式: 代码语言:javascript 复制 publicBuilder(){this.method="GET";this.headers=newHeaders.Builder();}publicBuilderget(){returnmethod("GET",null);}publicBuilderpost(RequestBody body){returnmethod("POST",body);}publicBuildermethod(String method,@Nullable RequestBody...
post 中的 Request.Builder() 函数不会接受 FormBody 作为参数,因为它需要一个 RequestBody,即使前者扩展了后者。 即使尝试直接使用他们的文档中的示例也会遇到同样的问题: val formBody = FormBody.Builder() .add("search", "Jurassic Park") .build() val request = Request.Builder() .url("https:/...
POST 请求: 代码语言:javascript 复制 publicstaticfinal MediaTypeJSON=MediaType.parse("application/json; charset=utf-8");OkHttpClient client=newOkHttpClient();Stringpost(String url,String json)throws IOException{RequestBody body=RequestBody.create(JSON,json);Request request=newRequest.Builder().url(url...