App Zugriff auf Webinhalt

  • Antworten:3
Moving Animations
  • Forum-Beiträge: 4

03.02.2013, 21:49:42 via App

Hey Leute,
ich hab eine Frage an euch, ich möchte mit meiner App mit manueller Passwort Eingabe auf einen geschützten Bereich zugreifen, also das Passwort und Benutzername mit senden. Leider kommt immer als Ergebnis das im WebView Fenster

Authorization Required

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.26 with Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g Server

ich hoffe ihr könnt mir helfen


Daaanke im vorraus

Antworten
Sebastian P.
  • Forum-Beiträge: 72

04.02.2013, 23:16:43 via Website

Ein Bisschen Code wäre hilfreich, z.B. wie die App die Daten überträgt.

Antworten
Moving Animations
  • Forum-Beiträge: 4

05.02.2013, 10:23:06 via Website

1try {
2 String data = "YOUR REQUEST BODY HERE"; // was muss ich hier eintragen
3 //
4 CredentialsProvider credProvider = new BasicCredentialsProvider();
5 credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
6 new UsernamePasswordCredentials("user", "pw"));
7 //
8 DefaultHttpClient http = new DefaultHttpClient();
9 http.setCredentialsProvider(credProvider);
10 //
11 HttpPut put = new HttpPut("url");
12 try {
13 put.setEntity(new StringEntity(data, "UTF8"));
14 } catch (UnsupportedEncodingException e) {
15 Log.e(TAG, "UnsupportedEncoding: ", e);
16 }
17 put.addHeader("Content-type","SET CONTENT TYPE HERE IF YOU NEED TO"); //muss hier was rein?
18 HttpResponse response = http.execute(put);
19 Log.d(TAG, "This is what we get back:"+response.getStatusLine().toString()+", "+response.getEntity().toString());
20 } catch (ClientProtocolException e) {
21 //
22 Log.d(TAG, "Client protocol exception", e);
23 } catch (IOException e) {
24 //
25 Log.d(TAG, "IOException", e);
26 }
27 webView = (WebView) findViewById(R.id.vPlan);
28 webView.getSettings().setJavaScriptEnabled(true);
29 //webView.loadUrl("");

Würde das so funktionieren, hab schon laaang gegoogelt nach einer lösung...

daaanke im vorraus

— geändert am 05.02.2013, 10:24:40

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

06.02.2013, 13:48:32 via Website

Google mal nach Android Post client
Oder mach bei der WebView wv.loadUrl(url);

— geändert am 06.02.2013, 13:49:37

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten