In loopj when i hit a URL nor onSuccess nor onFailure calling that's why my progressDiaog keep on running for infinite time.
Make sure you are implementing the right methods (different onSuccess/onFailure methods have different inputs).
If you are implementing onSuccess with input JSONObject but your WebService is returning a JSONArray, it will not enter there.
Related
I've overrided method delete in my Yii2 controller, but i can not call it from Android application with library Retrofit.
public function actionDelete($id)
{
$model=$this->findModel($id);
if($model->delete())
{
$this->setHeader(200);
echo json_encode(array('status'=>1,'data'=>array_filter($model->attributes)),JSON_PRETTY_PRINT);
}
else
{
$this->setHeader(400);
echo json_encode(array('status'=>0,'error_code'=>400,'errors'=>$model->errors),JSON_PRETTY_PRINT);
}
}
I tried 2 versions of calling:
first
#DELETE("posts/delete/{id}")
second
#DELETE("posts/{id}")
Call<Void> deletePosts(#Path("id") int id);
But I get error 404. So how should I correctly call this method?
When I try to call not overrided method I get error 500.
Maybe somebody knows how can I call delete method from Android to Yii2 rest?
Thanks in advance.
To pass a parameter as in public function actionDelete($id), you need to call /posts/delete?id=<id>, not just /posts/delete/<id>. However, getting this wrong should result in a HTTP 400 Bad Request error, not in a 404 Not Found error.
Possible reason for the 404 error: I assume $model=$this->findModel($id); is generated code. If so, it's likely throwing a NotFoundHttpException exception if a model with the given ID could not be found.
Another thing you can check is if a VerbFilter is configured in the behaviors() method of your controller to only allow POST requests for the delete action. You might be sending a GET request.
I am making a POST request using Retrofit, call executes successfully on rest client. Also onResponse of call executes but in response body i am getting error
'unicode' object has no attribute 'items'.
What is the reason of this error?
its my first time asking a question here, so please tell me if I missed to include something.
I have a method that prints returns a String. Inside it, is an asychronous volley request that retrieves a specific value to be added to the String. The problem is that the request is made, but since it's an asynchronous request, the method still proceeds and returns the String even if it still doesn't have the value from the request. The request completes afterwards. So the question is, is there a way to make the method wait for a specific variable to have a value before proceeding, without freezing the UI? Should I create a new thread instead?
Code below is not the actual codes I have but it shows the outline.
public String getStr{
StringBuilder sb = new StringBuilder();
String strOne;
// code here..
// asynchronous request here..
// code here..
sb.append(strOne)
// code here..
return sb.toString();
}
The asychronous request refers to the volley request.
Any help is appreciated. Thanks in advance!
You should handle the response in onResponse (#Override) method. Take a look in this tutorial:
Asynchronous HTTP Requests in Android Using Volley
If you want to return the response to another class to handle it there, I suggest you to implement an interface. I could post the code for this here, but I aswered a question like this here:
Volley , Wait for response to return wait until use flag - answer
1)I am caching the string network response from the server using the method
request.setShouldCache(true);
2)I am trying to access the cached data using
System.out.println("the cached data"+new String(request.getCacheEntry().data));
This throws a null pointer exception .
3)I printed a output statment in HTTPHeaderparser.java .The data is printed properly .
System.out.println("the data value is"+new String(entry.data) );
4)So i guess I made some mistake while fetching the cached data .
Can some one help me out ?
The cache entry in the request it's not filled until you run the request, so you should directly call the cache to test if it contains a value with
mQueue.getCache().get(request.getCacheKey())
as bogdan put in the comment if what you want to do is get a value from cache without making a network request.
this method is fast and you can call from the UI Thread. It will return the cache entry if available even if it's expired, but you can call the isExpired() method to know if the response it's outdated.
It returns the data even if stale, because you can choose to show it while you refresh the data in the background.
Take a look at the method parseCacheHeaders(NetworkResponse) from the class HttpHeaderParser. There are some conditions there for caching the response, so the library will only cache the response if the server will provide some headers. If you want to override this, you will have to override the method parseNetworkResponse(NetworkResponse) from the Request class and call a different method for parsing the cache headers from the server.
Update
It seems I misunderstood the question a bit, for accessing Volley cache, assuming your RequestQueue instance is mQueue, you can do mQueue.getCache().get(request.getCacheKey()).
From my experimenting so far, it appears that Volley accesses its cache based on the URL alone. I would like to know if it also can determine which response it should return based on the combination of URL and request body data.
Is there a setting for this, or and extension point where I can implement this myself.
I don't see anywhere that the request body data is returned in the NetworkResponse object, or I would do the check in the parseNetworkResponse method.
Thanks
You have to override Request.getCacheKey() method to include request body as well, when implementing your custom request.