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 8329891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:56:41+00:00 2026-06-09T01:56:41+00:00

I have a bit of Java code that attempts to send POST data over

  • 0

I have a bit of Java code that attempts to send POST data over to t Django application. However, the view is simply never called. If I paste the same URL the java code hits into my browser, the Django view is called. I have no idea what I am missing, but something must be wrong with the Java write.

This is the Java function doing the write:

public void executeWrite(String requestUrl, JsonObject jsonObject)
{
    DataInputStream  input = null;
    try
    {
        URL                 url;
        HttpURLConnection urlConn;
        DataOutputStream printout;

        System.out.println(requestUrl);
        // URL of CGI-Bin script.
        url = new URL (requestUrl);
        // URL connection channel.
        urlConn = (HttpURLConnection)url.openConnection();
        // Let the run-time system (RTS) know that we want input.
        urlConn.setDoInput (true);
        // Let the RTS know that we want to do output.
        urlConn.setDoOutput (true);
        // No caching, we want the real thing.
        urlConn.setUseCaches (false);
        // Specify the content type.
        urlConn.setRequestMethod("POST");
        urlConn.setRequestProperty("content-type","application/json; charset=utf-8");

        OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream());
        wr.write(jsonObject.toString());
        wr.flush();
        wr.close();
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
    }
}

Now the requestURL passed into the function directly corresponds to the one for the Django view. The requestURL is:

http://127.0.0.1:8000/events/rest/33456/create

This is the Django Urlconfig:

(r'^events/rest/(?P<key>\d+)/create', 'events.views.restCreateEvent'),

Finally this is the view that never gets called by the Java code

@csrf_exempt 
def restCreateEvent(request, key):
    #doesn't really matter what is in here it never runs

So, what am I doing wrong that the POST request is never received by the Django sever? I’ve spent about 2 hours trying to figure it out and I can’t find any issues with the Java code. Clearly something is wrong though.

  • 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-09T01:56:43+00:00Added an answer on June 9, 2026 at 1:56 am

    Make sure your view is csrf exempt since you are not sending the appropriate CSRF token from the Java request.

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

Sidebar

Related Questions

I have inherited a bit of Java code that uses Hibernate. Some of the
I have a bit of Java code that outputs an XML file to a
I have the following bit of code that reads data from the an Oracle
I have a java program that needs to tar/gz a large bit of data
I have read up on it a bit and I understand that in java
I have a rather memory hungry java application. On my 32 bit systems with
i have bit of code that causes an underflow: var t1, t2, delta: DWORD:
I am writing a Java code generator. I have an immutable Map that contains
Lets say i have the following bit of code import java.sql.Connection; import java.sql.DriverManager; import
I have the following bit of code that I am having some difficulty with.

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.