簡體   English   中英

500內部服務器錯誤Django Java

[英]500 Internal server error django java

我正在將Java發布請求(JSON對象)從我的Java應用發送到我的Django應用(在同一台機器上)。

我的Java請求部分代碼是:

    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();
    }

我的Python視圖功能如下:

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

    return StreamingHttpResponse("Unsuccessful")

來自Java的發布請求正在到達服務器,但出現錯誤:

HTTP / 1.0 500內部服務器錯誤[日期:2015年1月7日星期三,格林尼治標准時間,服務器:WSGIServer / 0.1 Python / 2.7.6,X框架選項:SAMEORIGIN,內容類型:text / html]

您不能將字符串傳遞給StreamingHttpResponse ,它必須是一個生成器。

在進行更改之前,您可以使用HttpResponse來測試上述內容。

HttpResponse("Your text here")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM