POST-Request gibt FileNotFoundException

POST-Anforderung gibt FileNotFoundException für die URL

Ich bin eine Http-POST-Anforderung an eine Url https://nitos.gr in android.

Die url muss nicht der domain-name. Stackoverflow nicht erlauben, mich zu URL mit Nummern in meinem text, also schreib ich einfach eine zufällige url https://nitos.gr dafür ein Beispiel.

Bekomme ich eine 400 - Antwort-code und drucken Sie den getErrorStream() geben libcore.net.http.UnknownLengthHttpInputStream@41eba330

Allerdings führe ich erfolgreich mit HTTP-GET-Anfrage. Die url ist https, also ich habe ein fake-trust-manager, so dass alle SSL-verbindungen.

In der Zusammenfassung:

Protokoll: HTTPS

GET-Anforderung: erfolgreiche

POST-Anforderung: Fehl

Anfrage code: 400

Fehlermeldung: java.io.FileNotFoundException: https://nitos.gr

ErrorStream: java.io.FileNotFoundException: https://nitos.gr

Die Methode der Durchführung der POST-Anforderung folgendermaßen:

public void setTestbedData(String path, String data) {
        HttpURLConnection con = null;

        try {
            con = (HttpURLConnection) ( new URL(Constants.BASE_URL + path)).openConnection();
             //If you invoke the method setDoOutput(true) on the URLConnection, it will always use the POST method.
            con.setRequestMethod("POST");
            con.setDoInput(true);
            con.setDoOutput(true);

            con.setRequestProperty("Accept", "application/json");
            con.setRequestProperty("Content-Type", "application/json");

            Log.i("data", data);    

            OutputStream outputStream = con.getOutputStream();
            outputStream.write(data.getBytes());
            outputStream.flush();

            Log.w("RESPONSE CODE", "code " + con.getResponseCode());

            Log.w("this is connection ",""+con); 
            InputStream errorstream = con.getErrorStream();             
            Log.w("GetErrorStream  ", ""+errorstream);

            InputStream _is;
            if (con.getResponseCode() >= 400) {  
                _is = con.getInputStream();  
            } else {  

                _is = con.getErrorStream();  

                String result = getStringFromInputStream(_is);
                Log.i("Error != 400", result);
            }


            if (con.getResponseCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : "
                    + con.getResponseCode());
            }



            BufferedReader responseBuffer = new BufferedReader(new InputStreamReader((con.getInputStream())));

            String output;
            Log.i("TestbedHttpClient","Output from Server:");
            while ((output = responseBuffer.readLine()) != null) {
                Log.i("Output",output);
            }

            con.disconnect();

            } catch (MalformedURLException e) {
                //TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                //TODO Auto-generated catch block
                e.printStackTrace();
            }

    }

Die Fehlermeldungen:

RESPONSE-CODE(18936): code 400
libcore.net.http.HttpsURLConnectionImpl$HttpUrlConnectionDelegate:https://nitos.gr
GetErrorStream(18936): libcore.net.http.UnknownLengthHttpInputStream@41eba330
System.err(18936): java.io.FileNotFoundException: https://nitos.gr
System.err(18936): bei libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)

  • Nicht ausgeben der Fehler-stream, aber Lesen Sie es und drucken Sie die Zeichen von Fehler-stream. Das wäre toll, um Ihnen zu helfen. BTW könnte man einigen Aufwand, um formatieren Sie Ihre post so Lesen wir es leicht.
  • Sorry, was meinst du mit Druck nur Zeichen? InputStream errorstream = con.getErrorStream(); Log.w("GetErrorStream ", ""+errorstream); Dies ist nicht richtig?
  • Um den Fehler-Strom sichtbar ist, müssen Sie sich mit ihm in der gleichen Weise, die Sie später Lesen Sie den Inhalt der input-stream (über BufferedReader). Dann werden Sie sehen, was der server sagt. Dies wird nur ein winziger Schritt weiter, zu wissen, was Sie gemacht haben, falsch...
InformationsquelleAutor zoe vas | 2014-08-23
Schreibe einen Kommentar