Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8796473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:37:52+00:00 2026-06-13T23:37:52+00:00

Jersey client is not setting the origin header for me and I wonder if

  • 0

Jersey client is not setting the “origin” header for me and I wonder if I am missing anything.

String origin="http://www.localhost.com";
ClientResponse response= webResourceBuilder("my/endpoint")
            .header( "origin" , origin)
            .header("Access-Control-Request-Method", "POST")
            .header("xorigin", origin)
            .header("whatever", "test")
            .accept("application/xml")
            .get(ClientResponse.class);

When I inspect at runtime the request headers on the server side, I find “xorigin” and “whatever” headers, but not “origin” and “Access-Control-Request-Method”

How can I set these headers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:37:54+00:00Added an answer on June 13, 2026 at 11:37 pm

    Default Jersey client uses HttpURLConnection to send requests to the server. HttpUrlConnection restricts some headers to be sent in a request, see:

    /*
     * Restrict setting of request headers through the public api
     * consistent with JavaScript XMLHttpRequest2 with a few
     * exceptions. Disallowed headers are silently ignored for
     * backwards compatibility reasons rather than throwing a
     * SecurityException. For example, some applets set the
     * Host header since old JREs did not implement HTTP 1.1.
     * Additionally, any header starting with Sec- is
     * disallowed.
     *
     * The following headers are allowed for historical reasons:
     *
     * Accept-Charset, Accept-Encoding, Cookie, Cookie2, Date,
     * Referer, TE, User-Agent, headers beginning with Proxy-.
     *
     * The following headers are allowed in a limited form:
     *
     * Connection: close
     *
     * See http://www.w3.org/TR/XMLHttpRequest2.
     */
    private static final boolean allowRestrictedHeaders;
    private static final Set<String> restrictedHeaderSet;
    private static final String[] restrictedHeaders = {
        /* Restricted by XMLHttpRequest2 */
        //"Accept-Charset",
        //"Accept-Encoding",
        "Access-Control-Request-Headers",
        "Access-Control-Request-Method",
        "Connection", /* close is allowed */
        "Content-Length",
        //"Cookie",
        //"Cookie2",
        "Content-Transfer-Encoding",
        //"Date",
        //"Expect",
        "Host",
        "Keep-Alive",
        "Origin",
        // "Referer",
        // "TE",
        "Trailer",
        "Transfer-Encoding",
        "Upgrade",
        //"User-Agent",
        "Via"
    };
    

    You have two options how to handle this situation:

    1. With the default Jersey client you need to set a system property

      -Dsun.net.http.allowRestrictedHeaders=true
      

      which suppresses removing restricted headers from the request.

    2. Use ApacheHttpClient/ApacheHttpClient4 which doesn’t seem to have this restriction. Simply add one of the following dependencies to your project:

      <dependency>
          <groupId>com.sun.jersey.contribs</groupId>
          <artifactId>jersey-apache-client</artifactId>
          <version>1.15</version>
      </dependency>
      

      or

      <dependency>
          <groupId>com.sun.jersey.contribs</groupId>
          <artifactId>jersey-apache-client4</artifactId>
          <version>1.15</version>
      </dependency>
      

      and then create your client like:

      ApacheHttpClient.create(com.sun.jersey.api.client.config.ClientConfig);
      

      or

      ApacheHttpClient4.create(com.sun.jersey.api.client.config.ClientConfig);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble with not getting connections when calling a rest api with com.sun.jersey.client.apache.ApacheHttpClient
My code is not working: package com.foo.json; import javax.xml.bind.annotation.XmlRootElement; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; @XmlRootElement
Im writing an android app that connects to my own Jersey rest client. HTTP
Is there any Java library to compute a Basic or Digest Http authentication? Jersey-Client
I am using Jersey client for http-based request. It works well if the file
I have a jersey client that is getting JSON from a source that I
I use jersey-client to consume a REST service. I need both the requested Entity
When positing large files as an InputStream using the Jersey client, it appears that
How do I send GET requests using the Jersey Client API to a server
I am working on a jersey rest client and I am building my client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.