我正在尝试将手段连接AsyncHttpClient到我网站上的PHP脚本.该脚本执行另一个页面的html解析,并将结果转换为json.它运作良好.但是,当我尝试将json形式的java用于在android上使用它时,只有打开流并返回"响应"的方法才会运行,onSuccess并且onFailure两者都不运行.谁能帮我?这里的代码:
private String getStream() {
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://jem88.net/eventsAroundYouParser.php", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
System.out.println("response is here..."+response);
Log.d("eventstaker", "into response!!");
}
@Override
public void onFailure(Throwable e, String response) {
Log.d("eventstaker", "onFailure method is run... :(");
}
});
return "";
}`
Run Code Online (Sandbox Code Playgroud)
我给自己定的internet,并network_access允许在清单.先感谢您
我创建了以下类:
public class AsyncHttpsClientHelper {
public static final int REMOVE_CREDIT_CARD = 1;
public static final int ENABLE_AUTORENEW = 2;
// +10 final ints...
private static AsyncHttpsClientHelper instance = null;
private static Activity activity;
// Some other variables
private AsyncHttpsClientHelper(Context context) {
// Initiate variables
}
public static AsyncHttpsClientHelper getInstance(Context context) {
// Guarantees the same instance for this class (Singleton)
}
public void performNetworkTask(int networkTaskType, String value)
{
switch (networkTaskType)
{
case REMOVE_CREDIT_CARD:
{
CupsLog.d(TAG, "path: " + Consts.ACCOUNT_REMOVE_CREDIT_CARD_PATH);
client.post(Consts.ACCOUNT_REMOVE_CREDIT_CARD_PATH …Run Code Online (Sandbox Code Playgroud) 我需要在几个方面使用loopj的SyncHttpClient。当我使用AsyncHttpClient时,请求成功返回。当我按此处接受的答案所示使用SyncHttpClient时:如何使用loopJ SyncHttpClient进行同步调用?,我在中遇到断点onFailure。该的StatusCode为0,错误响应是空的,抛出的java.io.IOException异常:未处理的异常:空。
这是相关的代码。再次,当我使用异步时,它工作正常:
buttonTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// AsyncHttpClient httpClient = new AsyncHttpClient();
SyncHttpClient httpClient = new SyncHttpClient();
httpClient.get("http://10.0.1.6:3000/home/test_endpoint", new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
String stringResponse = response.toString();
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
String error = errorResponse.toString();
}
});
String temp = "got here";
} …Run Code Online (Sandbox Code Playgroud) 我正在使用来自http://loopj.com/android-async-http/的AsyncHttpClient库,让它可以调用Web服务来检索JSON响应.我现在正试图调用一个Web服务,通过HTTP将文件流回客户端.因此我使用BinaryHttpResponseHandler来捕获返回的byte []数据.但是,每当我尝试调用该方法时它都会失败,并且在检查Throwable对象时,异常是'org.apache.http.client.HttpResponseException:不允许Content-Type!".
我已经尝试根据文档指定允许的内容类型列表,但这并没有什么不同.我主要是流式传输PDF,但理想情况下我不想指定内容类型列表,我希望能够下载任何文件类型.我正在使用的代码如下:
AsyncHttpClient httpClient = new AsyncHttpClient();
String[] allowedContentTypes = new String[] { "application/pdf", "image/png", "image/jpeg" };
httpClient.get(myWebServiceURL, new BinaryHttpResponseHandler(allowedContentTypes) {
@Override
public void onSuccess(byte[] binaryData) {
// ....
}
@Override
public void onFailure(Throwable error, byte[] binaryData) {
// ....
Log.e("Download-onFailure", error.getMessage());
}
});
Run Code Online (Sandbox Code Playgroud)
我还尝试不指定任何内容类型,只使用:
new BinaryHttpResponseHandler()
Run Code Online (Sandbox Code Playgroud)
但这并没有什么区别.
我正在尝试测试我的Android应用程序并将数据添加到localhost上托管的数据库.我使用ngrok打开了一个隧道来访问存储在我本地计算机上的数据库.这是我的代码:
public class MainActivity extends FragmentActivity{
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private static String email;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
private static final int RESULT_SETTINGS = 1;
private static String IP_ADDRESS="http://682dc364.ngrok.com/";
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Account[] accounts = AccountManager.get(getBaseContext()).getAccounts();
if(accounts.length …Run Code Online (Sandbox Code Playgroud) 我一整天都在寻找如何将图像从我的应用程序上传到服务器端.我已经完成了移动应用程序方面的工作
public static void postImage(String ImageLink){
RequestParams params = new RequestParams();
params.put("uploaded_file[name]", "MyImageName");
try {
params.put("uploaded_file[image]", new File(ImageLink));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
AsyncHttpClient client = new AsyncHttpClient();
client.post(MY_PHP_FILE_LINK, params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
System.out.println("statusCode "+statusCode);//statusCode 200
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
}
});
}
Run Code Online (Sandbox Code Playgroud)
和我的PHP边码
<?php
$file_path = "/uploads/";
$file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
echo "success"; …Run Code Online (Sandbox Code Playgroud) 我试图通过网站进行身份验证.我在用AsyncHttpClient.下面是我正在尝试的代码.
这是我的代码,
public class LoginActivity extends Activity {
String tag = "LoginActivity";
Button requestBtn;
AsyncHttpClient httpClient = new AsyncHttpClient();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
requestBtn = (Button) findViewById(R.id.upload_file);
PersistentCookieStore myCookieStore = new PersistentCookieStore(this);
httpClient.setCookieStore(myCookieStore);
httpClient.setBasicAuth(ApplicationConstants.userName,
ApplicationConstants.password, new AuthScope(
"http://*.*.*.*:8080/someUrl", 8080,
AuthScope.ANY_REALM));
requestBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
httpClient.get("http://*.*.*.*:8080/someurl",new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
System.out.println(response);
Log.d("Sucessful upload","Onsucess" + response);
}
@Override
public void onFailure(Throwable arg0,String arg1) {
Log.d("LoginActivity",arg0.toString());
arg0.printStackTrace();
super.onFailure(arg0, …Run Code Online (Sandbox Code Playgroud) 之前我使用的是Android的Default Http客户端,然后在http://loopj.com/android-async-http/找到了这个库.
当我在AsyncTask的doInBackground(String ... args)中使用这个库时,我注意到postExecute()在android-async-http返回之前完成.
如果我使用AsyncHttpClient,我不应该使用AsyncTask吗?如果我只使用AsyncHttpClient,有没有办法处理慢速互联网连接或互联网访问超时.
我是android的新手,请帮忙!
android connection-timeout android-asynctask android-async-http
我正在使用intent服务与服务器通信以获取应用程序的数据.在应用程序尝试访问或使用数据存储的变量之前,我希望应用程序等待它请求的数据被发回(希望意味着已请求数据的IntentService已经完成运行)我该怎么做呢?谢谢!
rest android android-internet intentservice android-async-http
我正在尝试使用:
AsyncHttpClient client = new AsyncHttpClient();
Run Code Online (Sandbox Code Playgroud)
它说:
无法解析符号“AsyncHttpClient”。
我正在使用最新的 Android Studio 和 build.gradle min:15 target:22
我在Google Play控制台上收到IllegalStateException,我无法重现,并且我不明白这是什么问题。
这是来自Google Play控制台的日志
java.lang.RuntimeException:
at com.loopj.android.http.AsyncHttpResponseHandler.onUserException (AsyncHttpResponseHandler.java:304)
at com.loopj.android.http.AsyncHttpResponseHandler.handleMessage (AsyncHttpResponseHandler.java:395)
at com.loopj.android.http.AsyncHttpResponseHandler$ResponderHandler.handleMessage (AsyncHttpResponseHandler.java:510)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:148)
at android.app.ActivityThread.main (ActivityThread.java:5441)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:628)
Caused by: java.lang.IllegalStateException:
at android.support.v4.app.FragmentManagerImpl.enqueueAction (FragmentManager.java:1515)
at android.support.v4.app.BackStackRecord.commitInternal (BackStackRecord.java:638)
at android.support.v4.app.BackStackRecord.commit (BackStackRecord.java:617)
at android.support.v4.app.DialogFragment.show (DialogFragment.java:139)
at com.example.eliran.forum.ForumFragment.regularTopic (ForumFragment.java:240)
at com.example.eliran.forum.ForumFragment.enterTopic (ForumFragment.java:225)
at com.example.eliran.forum.ForumFragment$13.onSuccess (ForumFragment.java:620)
at com.loopj.android.http.TextHttpResponseHandler.onSuccess (TextHttpResponseHandler.java:118)
at com.loopj.android.http.AsyncHttpResponseHandler.handleMessage (AsyncHttpResponseHandler.java:351)
Run Code Online (Sandbox Code Playgroud)
根据我所附的日志,流程如下:
在此功能(regularTopic)中,它发生了。这是函数:
public void regularTopic(ForumTopic forumTopic, int positionInArray) {
FragmentManager fm = getChildFragmentManager(); …Run Code Online (Sandbox Code Playgroud)android android-fragments android-dialogfragment android-async-http
我试图使用android httpclient(loopj)发布一些数据.我在其正文中添加一些json数据并设置请求标头.但它显示AsyncHttpClient:将忽略Passed contentType,因为HttpEntity设置了内容类型.有谁知道如何解决这个问题?
public static void post(Activity context,String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
try {
JSONObject jsonParams = new JSONObject();
JSONObject innerObject = new JSONObject();
innerObject.put("Name", "@MODE");
innerObject.put("ParamType", "8");
innerObject.put("Value", "0");
JSONArray ar = new JSONArray();
ar.put(innerObject);
try {
jsonParams.put("ProcName", "Core.MENUS_SPR");
jsonParams.put("dbparams", ar);
Log.i("jsonParams.toString()",""+jsonParams.toString());
StringEntity se = null;
try {
se = new StringEntity(jsonParams.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return;
}
client.post(context, (url), se, "application/json", responseHandler);
} catch (JSONException e) {
e.printStackTrace();
}
} catch (Exception e) { …Run Code Online (Sandbox Code Playgroud) android web-services loopj androidhttpclient android-async-http
我正在构建一个Android应用程序,它将REST使用HTTP和HTTPS下载JSON和文件数据与服务进行通信.我正在寻找一个HTTP网络库来使用和评估选项.我找到了一个看起来很好的AsyncHttpClient(loopj.com/android-async-http)看起来不错,我看到Instagram使用它,但我看到它是建立在Apache HttpClient库上的,我似乎记得在某处看到Apache库被遗忘了赞成HttpURLConnection.这是我应该关注的吗?我应该考虑另一个图书馆吗?如果这有所不同,我计划将2.1的最低Android SDK作为目标.