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]
POST
you could also check it with your browser via aGET
– Daniel Rucci