如何使用OKHTTP进行POST请求?如何使用、OKHTTP、POST

2023-09-06 10:07:49 作者:本仙女超甜

我读这张贴jsons到服务器的一些例子。

i read some examples which are posting jsons to the server.

有人说:

OkHttp是被Java提供的HttpURLConnection的接口的实现,它写的内容提供了一个输入流,不知道(或护理)什么格式化内容。

"OkHttp is an implementation of the HttpUrlConnection interface provided by Java. It provides an input stream for writing content and doesn't know (or care) about what format that content is."

现在我想打一个普通岗位的URL与名和密码PARAMS。

now i want to make a normal post to the URL with params of name and password.

这意味着我需要我自己做的EN $ C C的名称和值对成流$?

it means i need to do encode the name and value pair into stream by myself?

推荐答案

您需要连接code是通过自己与逃逸的&放大器;。或者你可以使用FormEn$c$cr从 Mimecraft 它给你一个方便的建设者。

You need to encode it yourself by escaping strings with URLEncoder and joining them with "=" and "&". Or you can use FormEncoder from Mimecraft which gives you a handy builder.

FormEncoding fe = new FormEncoding.Builder()
    .add("name", "Lorem Ipsum")
    .add("occupation", "Filler Text")
    .build();