在第一次http请求到Dreamfactory之后获取“ERR_EMPTY_RESPONSE”

时间:2016-04-15 12:25:22

标签: angularjs typescript dreamfactory

我正在尝试向Dreamfactory后端发出http请求。

public String  performPostCall(String requestURL, HashMap<String, String> postDataParams) {

    URL url;

    StringBuffer response = new StringBuffer();
    try {
        url = new URL(requestURL);

        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(15000);
        conn.setConnectTimeout(15000);
        conn.setRequestMethod("POST");
        conn.setDoInput(true);
        conn.setDoOutput(true);


        OutputStream os = conn.getOutputStream();
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(os, "UTF-8"));
        writer.write(getPostDataString(postDataParams));

        writer.flush();
        writer.close();
        os.close();
        int responseCode=conn.getResponseCode();

        if (responseCode == HttpsURLConnection.HTTP_OK) {
            String line;
            BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));

            while ((line=br.readLine()) != null) {
                response.append(line);
            }
            br.close();
        }
        else {
            response.append("");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return response.toString();
}
private String getPostDataString(HashMap<String, String> params) throws UnsupportedEncodingException {
    StringBuilder result = new StringBuilder();
    boolean first = true;
    for(Map.Entry<String, String> entry : params.entrySet()){
        if (first)
            first = false;
        else
            result.append("&");

        result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
        result.append("=");
        result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
    }

    return result.toString();
}

第一次请求后,任何请求都会返回错误:

  

净:: ERR_EMPTY_RESPONSE

1 个答案:

答案 0 :(得分:0)

更改此

return this.$http({
    method: "GET",
    url: http://.../DMO_emails?filter=nom%20LIKE%20%27xxx%25%27%20OR%20nom%20LIKE%20%27%25%20xxx%25%27,
    headers: {
        "X-Dreamfactory_Application-Name": "appName"
});

到这个

return $http({
    method: "GET",
    url: "http://.../DMO_emails?filter=nom%20LIKE%20%27xxx%25%27%20OR%20nom%20LIKE%20%27%25%20xxx%25%27",
    headers: {
        "X-Dreamfactory_Application-Name": "appName"
    }
});