###前提・実現したいこと
AndroidデバイスからjsonをGAEサーバに送信したい。
###発生している問題・エラーメッセージ
下記curlを送ると、正しくGAE側が処理をしてくれて、jsonが送信されます。
curl https://example.com/api/test -X POST -H 'User-Agent:Dalvik/2.1.0' -H "Content-Type: application/json" -d '{"key": "test"}'
しかしながら、Androiデバイス側からhttp通信をしようとすると、下記のエラーがAndroid Monitorに表示されてしまいます。調べてみると、どうやらサーバー側のエラーらしく、4◯◯や5◯◯エラーということだそうです。curlで返ってきているのですが、どうしてAndroid側からはエラーが出てしまうのでしょうか。
java.io.FileNotFoundException: http://example.com/api/test
###該当のソースコード(Android側)
@Override protected Void doInBackground(JSONObject... params) { HttpURLConnection httpURLConnection = null; URL url = null; String urlString = HOST_URL; Log.d(TAG, "doInBackground is called"); Log.d(TAG, "param[0]:" + params[0].toString()); try { url = new URL(urlString); httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setConnectTimeout(100000); httpURLConnection.setReadTimeout(100000); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setDoOutput(true); httpURLConnection.setDoInput(true); httpURLConnection.setRequestProperty("Accept-Language", "jp"); httpURLConnection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); httpURLConnection.connect(); InputStream inputStream = httpURLConnection.getInputStream(); String readSt = readInputStream(inputStream); Log.d(TAG, "bodyByte:" + readSt); OutputStream outputStream = httpURLConnection.getOutputStream(); PrintStream printStreams = new PrintStream(httpURLConnection.getOutputStream()); printStreams.print(params[0]); printStreams.close(); outputStream.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/27 07:00