1
votes

I am sending a Java post request(JSON object) from my Java app to my Django app(in same machine).

My code for java request part is:

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(myurl);
    String json = jsonobject;

    StringEntity entity = new StringEntity(json,"UTF-8");
    entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    post.setEntity(entity);
    try {
        HttpResponse response1 = client.execute(post);
        LOGGER.info("Reached " + response1);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

And my Python views function is as follows:

@csrf_exempt
def rcvr1(request):
    if request.method=="POST":
        try:
            return StreamingHttpResponse("here")
        except:
            return StreamingHttpResponse("not Here")

    return StreamingHttpResponse("Unsuccessful")

The post request from Java is hitting the server, but is giving error:

HTTP/1.0 500 INTERNAL SERVER ERROR [Date: Wed, 07 Jan 2015 14:00:11 GMT, Server: WSGIServer/0.1 Python/2.7.6, X-Frame-Options: SAMEORIGIN, Content-Type: text/html]

1
add DEBUG=True in your settings.py to see the errorUku Loskit
It is already true, but where does the error show ?Nikhil Garg
It would be in the response, you could dump more from your java client but since it fails before even checking POST you could also check it with your browser via a GETDaniel Rucci

1 Answers

0
votes

You can't pass a string into StreamingHttpResponse, it needs to be a generator.

Until you make that change you can test the above by using an HttpResponse instead.

HttpResponse("Your text here")