0
Ich versuche, eine JSON Get Anfrage an meine Rails-Anwendung zu senden:JSON Get Anfrage mit HttpURLConnection
url = new URL("http://10.0.2.2:3001/users/[email protected]&user_token=cCqzCaqbfCzAsRgBGty-");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
InputStream in = urlConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(in);
Leider meine Rails-Anwendung wird es als HTML-Verarbeitung:
Started GET "https://stackoverflow.com/users/[email protected]&user_token=cCqzCaqbfCzAsRgBGty-" for 127.0.0.1 at 2017-03-10 18:28:06 -0500
Processing by UsersController#show as HTML
Parameters: {"user_email"=>"[email protected]", "user_token"=>"cCqzCaqbfCzAsRgBGty-", "id"=>"14", "user"=>{}}
Completed 406 Not Acceptable in 3136ms (ActiveRecord: 2.3ms)
Wie kann ich Spezifiziere JSON Anfrage Format mit HttpURLConnection
?
Haben Sie versucht, den Header "Accept" zu setzen? – CzarMatt
@CzarMatt ja und das hat funktioniert, wie ich in der Antwort auf diese Frage zeige. – Donato
Doh, tut mir leid - das ist, was ich für nicht erfrischende Seite bekomme, bevor ich kommentiere. ;) – CzarMatt