来自GAE地址的getInputStream上的FileNotFoundException

时间:2016-05-01 22:26:10

标签: java android python google-app-engine

我正在使用带有Python的API进行Android应用。该API位于Google App Engine云上,当我使用Postman进行测试时,一切正常。

我正在尝试使用POST方法进行登录。该方法返回json与用户信息我一直收到该错误:FileNotFoundException

以下是我的一些代码:

try{
            String account = params[0].get(0);
            String password = params[0].get(1);

            URL url = new URL("http", WEB_SERVICE_URL, PORT, REST_LOGIN);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setConnectTimeout(CONNECTION_TIMEOUT);


            httpURLConnection.setRequestMethod("POST");


            httpURLConnection.setDoOutput(true);
            httpURLConnection.setRequestProperty("Content-Type", "application/json");
            httpURLConnection.setRequestProperty("Accept", "application/json");

            JSONObject json = jsonParser.serialJsonLogin(nomCompte, motPasse);


            osw = new OutputStreamWriter(httpURLConnection.getOutputStream(),"UTF-8");
            osw.write(json.toString());
            osw.flush();
            String body = readStream(httpURLConnection.getInputStream());
            osw.close();




            Log.i(TAG, "Return : " + body);

            user = jsonParser.deserializeJsonUser(body);

        }catch (Exception e) {
            mException = e;
        }finally {
            if (mHttpURLConnection != null) {
                mHttpURLConnection.disconnect();
            }
        }
        return user;

At:String body = readStream(httpURLConnection.getInputStream());我收到了java.io.FileNotFoundException:http://pubs.opengroup.org/onlinepubs/009695399/functions/fabs.html

我的readStream方法很好,我测试了它。如果我查看我的Google App Engine日志,我可以看到没有404,或者有任何错误。如果我找到用户,我得到201即使不是403.所以即使错误说FileNotFound,我看到状态代码,这意味着实际上URL是正确的。

更新:我的API给了我一个201,而getInputStream显然不适用于201状态。在我的API中将我的返回状态更改为200,它运行正常。

0 个答案:

没有答案