Jersey client transmits Chinese Parameters

Source: Internet
Author: User

The client requires the client package:

        <dependency>            <groupId>com.sun.jersey</groupId>            <artifactId>jersey-client</artifactId>            <version>1.18</version>        </dependency>

The version corresponds to the previous version.

The Code is as follows:

Package client; import COM. sun. jersey. API. client. client; import COM. sun. jersey. API. client. clientresponse; import COM. sun. jersey. API. client. webresource; import Java. io. unsupportedencodingexception; import java.net. urlencoder;/*** created by WL on 2014/10/15. */public class restfulclient {public static void main (string ARGs []) {string url = "http: // localhost: 8080/services/Hello/"; client Client client = client. create (); try {URL + = urlencoder. encode ("hello", "UTF-8");} catch (unsupportedencodingexception e) {e. printstacktrace ();} webresource resource = client. resource (URL); clientresponse response = resource. get (clientresponse. class); string entity = response. getentity (string. class); system. out. println (entity );}}

The corresponding server method:

// @ Get @ produces (mediatype. text_plain) @ path ("{name}") Public String sayhello (@ pathparam ("name") string name) {return "hello," + name ;}

Therefore, the result is printed:

Hello, how are you?

Jersey client transmits Chinese Parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.