How to check response for multiple requests in ASINetworkQueue? - iphone

I am using ASINetworkQueue to send multiple requests to the server one after another. I have 4 consecutive server calls.
I want to know whenever the response is received, I want to handle it in selector for queue. I have implemented handler method as well using
requestDidFinishSelector
I want to know how to get responsestring for each request individually? just like
[request responseString]
with normal http requests? How can I solve this? Thanks in advance.

Solved : solution found here in github itself
- (void)requestFinished:(ASIHTTPRequest *)request
{
//print or manipulate response here
}

Related

NSURLConnection delegate methods not giving the response immediately

Hi in my application I am using NSURLConnection delegate metods to get a response from the server.Here what is happening is when ever I send a request to the server for the first time I am getting response immediately.After that first request if I send same request to the server again immediately I am getting the response as null. But if i leave the ipad aside after sometime I am getting the response can you please let me know is there any time limit needed between the requests while sending to the server using NSURLConnection delegate methods.Please help me to resolve this issue.
Thanks in advance.

ASIHTTPRequest, request sent twice

I´ve just started using ASIHTTPRequest for iOs and I have a small issue with it. All requests are sent twice to the server even though I only get one reply from the library to my delegate methods.
Both sync and async requests have this issue. I use Xcode 4 with ARC but have disabled it for ASIHTTPRequest by adding -fno-objc-arc as compiler flags.
Any idea what´s wrong..?
Code:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
}
This has bitten me too. I was using a GET request to validate a multi-use voucher code on a server. When we added a rate limitation for redeeming codes some customers reported hitting the limit before they should have. Turns out that some of the validations triggered two redeems.
Your request is using the GET method.
The default behavior when using GET is to allow persistent connections (the Keep-Alive HTTP header).
When using a persistent connection your GET request might get retransmitted if something on the network looks wonky (that's a technical term) instead of the request just failing. This is usually desirable because GET requests often do not have any side effects on the server.
POST or PUT requests on the other hand default to not use a persistent connection and will not retransmit your operation, which could well be a credit card purchase or something else with significant side effects.
If you wish to prevent your ASIHTTPRequest GET sometimes sending 2 or more server requests (due to network issues outside your control) you can simply set this flag:
request.shouldAttemptPersistentConnection = NO;
This should take care of the spurious GET duplicates on the server.
Thank you for your replies. I moved to the new MKNetworkKit and never looked back at ASIHttpRequest. https://github.com/MugunthKumar/MKNetworkKit
Øystein
It might be sending a HEAD request to fetch the response size followed by a GET request to actually get the content. See this section of the documentation for more information.
It could be because persistent connections are in use, so you're seeing a failed request on a old connection followed by a working request on a new connection. (GregInYEG is also correct that it could be a HEAD request.)
If you gather a network trace using a tool like wireshark or charlesproxy then it would be possible to see exactly what is happening.

ASIHTTPRequest returns error 406 when trying to read RSS Feed

I'm trying to read the following URL: http://www.bandsintown.com/Godwrath/rss
My response string is empty and [request responseStatusCode] returns 406. I've tried adding the following with no success:
[request addRequestHeader:#"Accept" value:#"text/xml"];
[request addRequestHeader:#"Accept" value:#"application/rss+xml"];
Have any of you ever bumped into this problem?
Greets,
Shai.
Use CharlesProxy (or wireshark, or ...) to capture the http traffic from:
Your iOS app
A working client (eg. a web browser)
Compare the 2 and try to correct any differences (you can probably ignore User-Agent:, Connection:, If-Modified-Since: and a few other headers)
If you still can't get it working edit your question to add in the request captured in charlesproxy from the browser, your changed code to create the request and the request captured from your app.
406 generally means your browser doesn't understand the return data from the web server. In the example you give, you overwrite the Accept header. You can't provide the same header tag twice if I remember correctly...

Preventing ASIHTTPRequest from following HTTP 303 See Other

I'm writing an iPhone Application using the ASIHTTPRequest (http://allseeing-i.com/ASIHTTPRequest/) library for REST interactions to a Web App's RESTful services.
I am currently facing a bug where I am receiving a 200 OK from one of these pages and there is no body. Additionally, I noticed that the headers are blank after the request has been completed, but the headers were not blank beforehand (they were filled with an OAuth Authentication).
Through an over-complicated network / proxy setup, I was able to verify that I am receiving a 303 (as expected) and that ASIHTTPRequest is following that request (as semi-expected). However, since I need to recreate my OAuth authentication headers so that the RESTful services will give me the information I want, I need to prevent ASIHTTPRequest from following 303s, and instead to just return the 303 so I can read the Location header myself and create a new request with the appropriate OAuth Headers.
If anybody has had to do this, please let me know how you did it!
Thanks,
Tyler
Dives off the diving board into the NSAutoreleasePool
You can check your HTTP status in request:didReceiveResponseHeaders: delegate method. Here's the code:
- (void)request:(ASIHTTPRequest *)request didReceiveResponseHeaders:(NSDictionary *)responseHeaders {
if(request.responseStatusCode == 303) {
[request cancel];
}
}
- (void)requestFailed:(ASIHTTPRequest *)request {
if(request.responseStatusCode == 303) {
// here you can call your custom methods
}
}
It will cancel your connection as soon as it receives HTTP headers, so it will not load the full page.

ASIHttpRequest DELETE method with body parameters

I use ASIHttpRequest (v. 1.8-95) for Iphone and wanted to create a synchronous DELETE request together with some body data. I went this way:
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:nsUrl];
[request appendPostData:[#"some body params" dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:#"DELETE"];
[request startSynchronous];
Although I was confirmed on the client side via
NSLog(#"request: method:%#", request.requestMethod);
that the method was correctly set to "DELETE"
on the server side a "POST" request was received !
If I just omit
[request appendPostData: ..]
a correct DELETE is received on the server side)
So what's wrong with my request ?
Thanks for any solutions.
Regards
creator_11
Searching the asihttprequest group ( http://groups.google.com/group/asihttprequest/search?group=asihttprequest&q=delete&qt_g=Search+this+group ) turns up some relevant posts including a suggested workaround:
call buildPostBody on your request
after you've populated the body, but
before you set the request method.
HTTP verbs and usages can't just be mixed and matched. OK, they can, but you'd have to change the server to support your non-standard usage. DELETE should use the URI of the resource to be deleted, and thats it. No POST params, no attachment.
If really you want to send a little extra data along with the delete, you can set it in the headers of the request (addRequestHeader:value:), and server side pull that info out, but avoid that if you can. The reason is, the DELETE should be deleting one 'thing' referred to by it's URI. If the business logic of the server application says that delete should affect some other objects (eg cascading delete), the client application shouldn't know about that.
Can you explain what you're trying to POST while performing a DELETE, maybe I can offer an alternative solution.