Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将注释卷曲到jersey客户端_Java_Curl_Jersey_Jersey Client - Fatal编程技术网

Java 如何将注释卷曲到jersey客户端

Java 如何将注释卷曲到jersey客户端,java,curl,jersey,jersey-client,Java,Curl,Jersey,Jersey Client,如何向jersey客户端添加bellow curl注释 curl -X POST --user 'gigy:secret' -d 'grant_type=password&username=peter@example.com&password=password' http://localhost:8000/gigy/oauth/token 我试着喜欢贝娄。但我不知道如何添加其他内容 Client client = Client.create(); WebResource web

如何向jersey客户端添加bellow curl注释

curl -X POST --user 'gigy:secret' -d 'grant_type=password&username=peter@example.com&password=password' http://localhost:8000/gigy/oauth/token
我试着喜欢贝娄。但我不知道如何添加其他内容

Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8000/gigy/oauth/token");
-用户'gigy:secret'

你需要。基本上,您需要使用值Basic base64gigy:secret设置授权头,其中base64是用于将字符串user:password转换为其Base 64对应项的值。您可以在WebResource上设置标题,并调用其header方法

-d'grant_type=密码和用户名=peter@example.com&密码=密码'

这些是application/x-www-form-urlencoded参数。这是您需要作为请求的实体体发送的内容。有了Jersey,你可以使用这个类。创建后,只需向其添加键值/对,如key=grant\u type和value=password。所有对都被&分割

隐式媒体类型

当您没有在cURL请求中设置Content-Type头时,POST将默认为application/x-www-form-urlencoded。您需要在调用header后使用typeMediaType函数设置此项。使用MediaType.APPLICATION\u FORM\u URLENCODED\u类型

-X柱

现在您需要发送请求。只需在调用type之后调用post,并使用以下参数。postClientResponse.class,yourForm。这将返回一个ClientResponse