我到处搜索但我找不到答案,有没有办法发出简单的HTTP请求?我想在我的某个网站上请求PHP页面/脚本,但我不想显示该网页.
如果可能的话我甚至想在后台(在BroadcastReceiver中)这样做
我试图使用ListUtils,但当我运行应用程序时,我收到此错误:
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.commons.collections.ListUtils" on path: DexPathList[[zip file "/data/app/com.meridianaspect.wiw-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
Run Code Online (Sandbox Code Playgroud)
所以我想我必须以某种方式通过gradle导入该库,但我不知道该怎么做?
我想在Android Studio中使用这些库:
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
Run Code Online (Sandbox Code Playgroud)
我正在关注导师使用Eclipse的视频教程,所以我知道它有效.
但是我需要添加哪些额外的东西/库才能使用Android Studio?
目前我使用HttpClient,HttpPost将数据发送到我的PHP server从Android app,但所有这些方法是在API 22弃用,在API 23取出,那么有什么替代方案呢?
我到处搜索,但没有找到任何东西.
我正在研究项目,使用dom解析器获取页面源代码,在vb.net中的字符串中获取html源代码.
1)我想在android中实现相同的功能,通过在android中调用url来获取网页源代码的方法是什么.2)我将在一个布局中有两个源代码布局,而在网页本身有两个布局.如果我要更改源代码布局中的标题标记值,它必须在实际网页上自动更新?
什么是在Android中做到这一点的最佳方法?
任何形式的帮助将受到高度赞赏.
首先抱歉我的英语不好我是 android studio 1.4 的新手,我在 HttpClient 中遇到错误
错误
C:\Users\madhu\AndroidStudioProjects\LoginAndsign\app\src\main\java\com\login\loginandsign\SimpleHttpClient.java
Error:(27, 20) error: cannot find symbol class HttpClient
Error:(34, 20) error: cannot find symbol class HttpClient
Error:(36, 31) error: cannot find symbol class DefaultHttpClient
Error:(40, 13) error: cannot find symbol variable ConnManagerParams
Error:(57, 13) error: cannot find symbol class HttpClient
Error:(58, 13) error: cannot find symbol class HttpPost
Error:(58, 36) error: cannot find symbol class HttpPost
Error:(59, 13) error: cannot find symbol class UrlEncodedFormEntity
Error:(59, 51) error: cannot find symbol class …Run Code Online (Sandbox Code Playgroud) 我使用isReachable,但它不起作用,我使用了ConnectivityManager和getNetworkInfo; 实际上这只是为了检查我是否连接到互联网...
但问题是我想检查我是否可以访问互联网,所以我想ping网站以检查是否有回复.
public class UploadProfilePicActivity extends Activity implements View.OnClickListener {
ImageView imageView;
Button btnUploadPic;
Button btnskipUploadPic;
Button btnSaveNContinue;
private static int RESULT_LOAD_IMAGE = 1;
String imagepath = null;
ProgressDialog dialog = null;
String url_profilePic;
private int serverResponseCode;
String api = "http://192.168.2.17:8000/api/v1/";
String format = "/?format=json";
AlmabayDatabase almabayDatabase;
String encodedString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_uploadprofilepic);
imageView = (ImageView) findViewById(R.id.imageView);
btnUploadPic = (Button) findViewById(R.id.btnUploadPic);
btnskipUploadPic = (Button) findViewById(R.id.btnSkipUploadPic);
btnSaveNContinue = (Button) findViewById(R.id.btnSaveNContinue);
btnUploadPic.setOnClickListener(this);
btnSaveNContinue.setOnClickListener(this);
url_profilePic = api + "user-media" + format; …Run Code Online (Sandbox Code Playgroud) 我有一个Android项目,我需要使用http调用.
我使用这个简单的代码:
public void onGetClick(View v) {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.google.com");
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader
(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
Log.d("WM.ALS", line);
}
}
Run Code Online (Sandbox Code Playgroud)
但我找不到HttpClient库.
我将从Apache下载的.jar文件(http://hc.apache.org/downloads.cgi)添加到dir/lib中,并添加到"build.gradle(Module:app)"文件中,我补充说:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.0.1'
compile 'org.apache.httpcomponents:httpcore-4.4.3'
compile 'org.apache.httpcomponents:httpclient-4.5.1'
Run Code Online (Sandbox Code Playgroud)
}
但仍然无法工作..
我该怎么办?
android ×9
java ×2
api ×1
connection ×1
eclipse ×1
gradle ×1
http-post ×1
image-upload ×1
ping ×1