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

  • Home
  • SEARCH
  • 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 6180497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:51:11+00:00 2026-05-24T00:51:11+00:00

My problem is that I want to use Java to implement an application which

  • 0

My problem is that I want to use Java to implement an application which sends an HTTP GET request to some website. However, the target website needs one cookie to be set:

ShippingCountry=US

If this cookie is not set it returns bad indications. Below are my code segment and I get null from connect().

String urlString = "http://www1.macys.com/catalog/index.ognc?CategoryID=5449&viewall=true";
    try{
    URL url = new URL(urlString);
    URLConnection connection = url.openConnection();

    connection.addRequestProperty("Cookie", "ShippingCountry=US");
    connection.connect();

    // Create file 
    FileWriter fstream = new FileWriter("d:/out.txt");
    BufferedWriter out = new BufferedWriter(fstream);
    BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    StringBuffer sb = new StringBuffer();
    String line;
    while ((line = rd.readLine()) != null)
    {
        out.write(line);
    }
    rd.close();
    //Close the output stream
    out.close();

}

Can somebody help me?

  • 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-05-24T00:51:11+00:00Added an answer on May 24, 2026 at 12:51 am

    Just a guess but perhaps you might need setRequestProperty instead of addRequestProperty, since there can be only one Cookie string in a request.

    connection.setRequestProperty("Cookie", "ShippingCountry=US");
    

    If you need to send multiple cookie values you tack them on with colons:

    connection.setRequestProperty("Cookie", "ShippingCountry=US;OtherValue=2");
    

    Update:

    I tried doing a GET request using python and it looks like I get a 500 error. Perhaps the server is blocking the request because it doesn’t look like a web browser. Maybe adding the following headers will work:

    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7) AppleWebKit/534.48.3 (KHTML, like Gecko) Version/5.1 Safari/534.48.3
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-us
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    

    In particular the Accept and User-Agent headers might be required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VIM in Windows. The problem is that I want to use
The problem I'm having with writing a web application architecture is that I want
I want to create a C++ cross-platform (Windows and MacOS X) application that sends
My problem is that I want a grid that is populated with a set
Never used a cache like this before. The problem is that I want to
I have a class that i want to push_back into a deque. The problem
I'm working with CoreData in Cocoa (not document-based). My problem is, that I want
I'm troubleshooting a problem with creating Vista shortcuts. I want to make sure that
We are extending our java application to support plugins. Part of that includes keeping
I want a nice way to get the current unix timestamp from a java

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.