Tôi cố gắng để truy cập Basecamp API từ mã nguồn Android/Java của tôi sau cách ....HTTPS liên quan đến kết quả auth cơ bản vào Unauthorized
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class BCActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DefaultHttpClient httpClient = new DefaultHttpClient();
//final String url = "https://encrypted.google.com/webhp?hl=en"; //This url works
final String url = "https://username:[email protected]/people.xml"; //This don't
HttpGet http = new HttpGet(url);
http.addHeader("Accept", "application/xml");
http.addHeader("Content-Type", "application/xml");
try {
// HttpResponse response = httpClient.execute(httpPost);
HttpResponse response = httpClient.execute(http);
StatusLine statusLine = response.getStatusLine();
System.out.println("statusLine : "+ statusLine.toString());
ResponseHandler <String> res = new BasicResponseHandler();
String strResponse = httpClient.execute(http, res);
System.out.println("________**_________________________\n"+strResponse);
System.out.println("\n________**_________________________\n");
} catch (Exception e) {
e.printStackTrace();
}
WebView myWebView = (WebView) this.findViewById(R.id.webView);
myWebView.loadUrl(url);//Here it works and displays XML response
}
}
URL này hiển thị phản ứng trong WebView
, nhưng cho thấy ngoại trừ trái phép khi Tôi cố gắng truy cập thông qua HttpClient
như được hiển thị ở trên.
Đây có phải là cách phù hợp để truy cập API Basecamp thông qua Android/Java không? hoặc Vui lòng cung cấp cho tôi một cách phù hợp để làm như vậy.
Tôi đã chỉnh sửa câu trả lời của tôi. ;) – CSchulz
Bạn đã đọc nhận xét của tôi chưa? Bạn đang cố gắng sử dụng phiên bản * HttpClient * 4.x và cần thư viện và ** thay đổi thứ tự của các thư viện **! – CSchulz
Thư viện * HttpClient * phải nằm trước thư viện Android. Tôi không biết bạn đang sử dụng IDE nào. Trong nhật thực, bạn có thể làm điều đó trong * thuộc tính dự án * -> * đường dẫn xây dựng java * -> * thứ tự và xuất * – CSchulz