pokeb / asi-http-request
- Source
- Commits
- Network (38)
- Issues (2)
- Downloads (56)
- Wiki (1)
- Graphs
-
Branch:
master
Pledgie Donations
Once activated, we'll place the following badge in your repository's detail box:
Easy to use CFNetwork wrapper for HTTP requests, Objective-C, Mac OS X and iPhone
-
ASIHTTPRequest wont cancel when it is downloading data
1 comment Created 5 months ago by nskboyI noticed strange thing with ASIHTTPRequest when it downloads ~50Kb image over slow cellular connection. In my code I configure ASIHTTPRequest to download ~50Kb image over cellular network. When user wants to cancel the download I send
-[NSOperationQueue cancelAllOperations]to cancel the request. ASIHTTPRequest's delegate receivesrequestDidFailed:message with ASIRequestCancelledErrorType error. But afterwards delegate receivesrequestDidFinished:message with properly downloaded image. To workaround this issue I send-[ASIHTTPRequest cancel]inrequestDidFailed:if request failed with error ASIRequestCancelledErrorType.I think it's a bug.
Comments
-
I don't have really good reproduce instructions for you on this one because it is so rare but it does happen. I use a standard NSOperationQueue to push all ASIHTTPRequests into and I push a lot of requests through it limited to 4 simulataneously.
Around line 717 of ASIHTTPRequest.m there are (rare) occasions when the readStream is NULL and
the following line crashes the app:[self setTotalBytesSent:[[(NSNumber *)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue]];
Comments
Hi
Someone else reported a similar issue earlier this week. I have a what I hope is a fix sorted out, will push it up to GitHub tomorrow.
ta
Ben
Thanks Ben! Sorry I didn't send a patch with the bug. If only there
was more time in each day...This fix is on GitHub now, do let me know if you are still having problems!
Thanks
Ben
Looks good to me so far after some testing. Thanks Ben.
-
Seems like asi-http-request is throwing away the POST request body on the second request.
Comments
Hi
Thanks for your report. Can you provide more information on how you are supplying credentials? (eg [request setUsername:], the built-in dialog, via your delegate, etc)
Thanks
Ben
We're providing credentials using setUsername: and setPassword in the authenticationNeededForRequest delegate method.
Actually we've pinpointed the problem. It only occurs when the ASIFormDataRequest object includes file data to post, added using the setFile:forKey method.
I can give you a sample app if required.
Ok, have found the problem. The setFile / setData methods trigger the post body to be streamed from disk, and it looks like the temporary file ASIHTTPRequest creates for the body is being deleted when authentication fails.
Will try to get a fix up in the next couple of hours.
b
I think this problem should be fixed in the last commit - can you try it out your end?
Thanks
Ben
-
I'm setting the credentials with using setUserName and setPassword in the delegate method authenticationNeededForRequest. If credentials are wrong the app crashes.
It looks like the authentication delegate method is being called 3 times before the crash occurs, and from what I understand from the code this shouldn't be happening, and the request should just fail if the authorisation attempt count is 2.
The crash occurs on the line "[self setRequestCredentials:nil];" in ASIHTTPRequest's "attemptToApplyCredentials".
I have an example app if necessary.
Comments
Ignore 'authenticationRetryCount', it is only used for handling NTLM authentication. I don't think there's any limit on the number of times authenticationNeededForRequest can be called, assuming the wrong credentials are supplied each time.
A sample project would be really helpful => ben@allseeing-i.com.
Thanks!
Ben
-
responseString returns nil and responseData returns data
3 comments Created 3 months ago by uprise78The issue is with the following url and any url after this (replace the 100 with 200, 300, 400, etc):
http://www.craigslist.org/about/best/all/index100.htmlThe first page of the 'best of' section (http://www.craigslist.org/about/best/all/) works fine. For all other pages responseString returns nil due to trying to convert the responseData (which is properly downloaded) with the wrong encoding. ASI tries to use UTF8 when the actual data is ASCII (or at least using NSASCIIStringEncoding will allow the data to be converted to string).
This may or may not be an ASI issue. I will see if I can get some more info and a fix or if it is just a craigslist.org issue with sending different encoding and actual data.
Comments
This is definitely an issue with craigslist. The headers specify the content is in UTF8, while the page content itself is in Latin 1. You can test this yourself by changing the encoding in Safari, all the odd question mark characters are replaced with the characters they are supposed to represent when you set the text encoding to Latin 1. ASIHTTPRequest will default to Latin 1 unless the HTTP headers tell it the otherwise, so the HTTP header is tripping it up.
You can have a mismatch between the HTTP headers and the charset specified in HTML or XML content, I think browsers will always give precedence to the later, though ASIHTTPRequest won't attempt to read charsets from the page content. In this case, craigslist doesn't specify a charset in the HTML anyway.
I expect the issue doesn't show up on the first page because it doesn't contain any non-ascii characters.
You could workaround this issue by setting responseEncoding to NSISOLatin1StringEncoding.
As always, you are the man. Thanks for looking into this.
-
[PATCH] Properly encoding form data + setting correct character set header.
5 comments Created 3 months ago by lhunathThe following patch adds proper URL encoding of form data to ASIFormDataRequest. It also sets the charset to UTF-8, the charset that is used throughout ASIFormDataRequest to encode strings into data.
Without the former, URL injection is easily possible and people could just pass maliciously crafted data to an application to forge an incorrect request.
Without the latter many servers misinterprete the form data as ISO-8859-1 and certain characters get manhandled.
diff --git a/device/iphone/safe-online-iphone-client/Sources/ASIHttpRequest/Classes/ASIFormDataRequest.h b/device/iphone/safe-online-iphone-client/Sources/ASIHttpRequest/Classes/ASIFormDataRequest.h index a0991ad..dbc73ed 100644 --- a/device/iphone/safe-online-iphone-client/Sources/ASIHttpRequest/Classes/ASIFormDataRequest.h +++ b/device/iphone/safe-online-iphone-client/Sources/ASIHttpRequest/Classes/ASIFormDataRequest.h @@ -26,6 +26,9 @@ typedef enum _ASIPostFormat { ASIPostFormat postFormat; } +#pragma mark utilities ++ (NSString*) encodeURL:(CFStringRef) string; + #pragma mark setup request // Add a POST variable to the request diff --git a/device/iphone/safe-online-iphone-client/Sources/ASIHttpRequest/Classes/ASIFormDataRequest.m b/device/iphone/safe-online-iphone-client/Sources/ASIHttpRequest/Classes/ASIFormDataRequest.m index 803cf33..29c7827 100644 --- a/device/iphone/safe-online-iphone-client/Sources/ASIHttpRequest/Classes/ASIFormDataRequest.m +++ b/device/iphone/safe-online-iphone-client/Sources/ASIHttpRequest/Classes/ASIFormDataRequest.m @@ -19,6 +19,17 @@ @implementation ASIFormDataRequest +#pragma mark utilities ++ (NSString*) encodeURL:(CFStringRef)string +{ + CFStringRef result = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, + string, + NULL, + CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"), + kCFStringEncodingUTF8); + return [(NSString*) result autorelease]; +} + #pragma mark init / dealloc + (id)requestWithURL:(NSURL *)newURL @@ -181,7 +192,7 @@ return; } - [self addRequestHeader:@"Content-Type" value:@"application/x-www-form-urlencoded"]; + [self addRequestHeader:@"Content-Type" value:@"application/x-www-form-urlencoded; charset=UTF-8"]; NSEnumerator *e = [[self postData] keyEnumerator]; @@ -189,7 +200,7 @@ int i=0; int count = [[self postData] count]-1; while (key = [e nextObject]) { - NSString *data = [NSString stringWithFormat:@"%@=%@%@",[key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[[[self postData] objectForKey:key] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],(i<count ? @"&" : @"")]; + NSString *data = [NSString stringWithFormat:@"%@=%@%@", [ASIFormDataRequest encodeURL:(CFStringRef)key], [ASIFormDataRequest encodeURL:(CFStringRef)[[self postData] objectForKey:key]],(i<count ? @"&" : @"")]; [self appendPostData:[data dataUsingEncoding:NSUTF8StringEncoding]]; i++; }Comments
kevinoneill
Mon Sep 28 22:05:52 -0700 2009
| link
i applied this patch and it sorted out problems i was having with posting fields with special characters (eg &).
-k.
note that the charset should be specified in a few more places. See http://github.com/lhunath/asi-http-request/commit/747280371a7e1c6155e6acb611c657b557abc3a9
Awesome, thanks, both. :)
Will do some testing over the next couple of days, and get this patch merged in.
Thanks again!
Ben
Ok, this is in the newest version, and I have updated the test based on Alessandro's post to the google group. Please let me know if you find any problems!
Thanks
Ben
-
We were discussing it in this post of the group:
http://groups.google.com/group/asihttprequest/browse_thread/thread/1aad7e268ed1444e
It would be interesting that we could set the character encoding of the form requests
Thank you
Comments
This sounds like a great idea, thanks!
Will get something sorted once I've had a chance to catch up on the google group discussions.
Best!
Ben
Ok thank you.
Feel free to contact me to make any test if needed.
Regards.
Ok, have added stringEncoding property to ASIFormDataRequest. Please give it a try and let me know how you get on.
-
No Progress for ASIS3Request's queued in ASINetworkQueue
11 comments Created 2 months ago by mobilemeltingI've setup multiple ASIS3Request's and added them to a ASINetworkQueue.
The S3 Requests have a download and temporary download path, resume download is allowed.I've setup a UIProgressView as downloadProgressDelegate for the queue.
However it seems that the progress is not updated.
I've debugged the methods:
- (void)incrementDownloadSizeBy:(unsigned long long)bytes and
- (void)incrementDownloadProgressBy:(unsigned long long)bytes in the ASINetworkQueue class and both times the "bytes" value passed to these methods is 0.Any ideas how to solve this?
Comments
Hi
Have you set showAccurateProgress to YES on the queue?
Thanks
Ben
mobilemelting
Tue Oct 20 10:29:12 -0700 2009
| link
Yes I did that.
[self setNetworkQueue:[ASINetworkQueue queue]]; [[self networkQueue] setShowAccurateProgress:YES];I've debugged the ASIHTTPRequest class. In the method
- (void)updateDownloadProgress it seems that the "responseHeaders" is empty, because the "if" always fails. // We won't update download progress until we've examined the headers, since we might need to authenticate if (responseHeaders) {
.....If the response headers are empty, it's unlikely to be downloading any data at all.
Did you start the queue ([[self networkQueue] go]?) If so, are you getting an error in your requestDidFailSelector delegate method?
mobilemelting
Tue Oct 20 10:51:55 -0700 2009
| link
Well the data is downloaded.
I've setup the delegate methods like you recommended in the gist http://gist.github.com/150447:
/> [[self networkQueue] setRequestDidFinishSelector:@selector(requestFinished:)]; [[self networkQueue] setRequestDidFailSelector:@selector(requestFailed:)]; [[self networkQueue] setQueueDidFinishSelector:@selector(queueFinished:)];However none of the delegate methods is called (I've added log messages).
Not even the "queueFinished" delegate method. Although the data is downloaded successfully.
mobilemelting
Tue Oct 20 22:57:38 -0700 2009
| link
Source can be found here: http://gist.github.com/214556
mobilemelting
Tue Oct 20 23:55:51 -0700 2009
| link
If I do set the UIProgressView Delegate directly for each s3Request it works.
// [s3Request setDownloadProgressDelegate:[dc progress]];
However this causes the progress bar to flicker, because each s3Request reports its own
progress. It seems that the ASIS3Request is capable of reporting progress. But the queue
seems to be unable to query and summarize the request's progress.Ok, I think I see the problem. It will work when accurate progress is off, but not when it is turned on. ASIS3Requests don't have their HEAD request built properly when using an ASINetworkQueue. Will try to fix this morning.
Refactor ASIHTTPRequest, ASIS3Request to allow HEAD requests created by ASINetworkQueues to override headers on their main request
This should fix accurate progress tracking for ASINetworkQueues containing ASIS3Requests
Added progress test for ASIS3Request
Hopefully closed by 47b4e2cOk, this was a bit more tricky to fix than I thought... can you try with the latest version and let me know if it seems to be working now?
mobilemelting
Fri Oct 23 03:13:44 -0700 2009
| link
Perfect!
Works like a charm!
Thanks! -
Can ASINetworkQueue get a NSDictionary "userInfo" ?
8 comments Created 2 months ago by mobilemeltingIn order to distinguish between multiple queues it would be great if ASINetworkQueue gets a "userInfo" NSDictionary.
I've already added it to this gist source here: http://gist.github.com/215015
Comments
Hi again
Can you explain more about when you might need to be able to do this? In general you should avoid having several queues in use at the same time, if requests are running in each it will degrade performance and increase the chances that requests will timeout.
Perhaps you'd like to use a feature like this in some other way, if I can understand more about why you want this, it will help. :)
Best
Ben
mobilemelting
Fri Oct 23 02:59:34 -0700 2009
| link
Actually I don't run multiple queues at the same time. Its always one after the other.
But, when a queue is finished I want to broadcast some events. Therefore I need some information about the resources this queue and its request have been working on.
In my case I mark a "container" for download. This container has information about resources, which should be downloaded. So I create a queue for this container and add multiple request for the single downloads. I start the queue and when its finished I want to trigger some events to let the application know that the resources (a.k.a. container) are now available locally.
I figured that having a NSDictionary 'userInfo' for storing this kind of information with the queue would be a good thing.
Ok, cool. I'll add this in the next couple of days.
Alternatively, if you create an ASIHTTPRequest fork on GitHub (it's really easy if you haven't done it before) and publish this change there, I can merge it in easily and you'll be credited as the author directly in the commit.
Thanks
Ben
mobilemelting
Mon Oct 26 09:40:27 -0700 2009
| link
Hi Ben,
I've forked your project and added the NSDictionary "userInfo" addition to ASINetworkQueue. Please find the fork here: http://github.com/mobilemelting/asi-http-request
mobilemelting
Mon Oct 26 09:41:08 -0700 2009
| link
Do I need to do anything else or can you simple merge this into your trunk?
Great, thanks very much! I'll merge it in later this week.
One small issue - the dictionary needs to be a retained property.
Best,
Ben
mobilemelting
Tue Oct 27 14:49:10 -0700 2009
| link
Fixed that and commited to the branch.
-
In the right circumstances, the same request is able to call both its success and failure delegate methods, this shouldn't be possible. Must have been broken as a result of recent changes.
Comments
-
apple has updated its reachability class to version 2.0 which currently breaks ASIHTTPRequest
Comments
-
S3 upload file missing data on device, but not on simulator
5 comments Created about 1 month ago by rpstro02I'm experiencing an issue with an Amazon S3 file upload. The simulator works great. But the exact same code on the device doesn't seem to upload the entire 166 Kb .png picture file. It only seems to upload 159 Kb. When I try to open the image, I get an error. I've tried both 3G network and WiFi. Both with the same result. Anyone experienced this issue or know what the problem could be? I am on an iPhone 3Gs running OS 3.1.
Comments
Update. The issue seems to only be with PNG files. I think it might be similar to the same problem that occurs on the cocoahttpserver here:
http://code.google.com/p/cocoahttpserver/issues/detail?id=15#c4
I'm not sure what the deal is with png files on the iPhone.
I think I could fix the issue the same way the cocoahttpserver fixes the issue if I stream a file from memory as opposed to from the disk. I'm not sure how to do that right now. If anyone does, please post.
Are you trying to upload a png you added to your project?
If I'm reading it correctly, the problem on the link you sent seems to be related to Xcode pre-multiplying the alpha on the image, which makes the png unreadable by other apps.
To use the fix they suggest, try something like this:
UIImage imagePNG= [UIImage imageWithContentsOfFile:filePath];
NSData pngData= UIImagePNGRepresentation(imagePNG);
[pngData writeToFile:somewhere atomically:NO]; ASIS3Request *request = [ASIS3Request PUTRequestForFile:somewhere withBucket:bucket path:path];Writing it back to a file is necessary because ASIS3Request doesn't have support for uploading data except from a file, though I think this would be a worthwhile addition to the class.
Thanks
Ben
Thanks for the reply. I'm trying to upload a png that I added to the project bundle. I tried to read the file straight from disk. I will try what you're suggesting. I am pretty sure there is some sort of issue with the alpha on the image because when I view image info of the uploaded file, it's different from the alpha value of the original image.
Uploading from data would rock!
-
Been using the File upload for quite some time and every since 3.1 came out on the iPhone I get the error "Domain=ASIHTTPRequestErrorDomain Code = 1 UserInfo == xxxx 'A connection failure occurred: SSL problem (possibly a bad/expired/self-signed certificate)'"
Our hosting provider assures us all is good on the cert/config areas.
This is totally random and when I am good 3G coverage. I can immediately retry and it may or may not work. Not sure if this is an issue in the ASI code just wanted to toss it out there in case anyone else is having this.
Comments
Hi
Sorry for the delay in getting back to you on this, I've been away for a couple of weeks.
Hmm, that does sound like a curious issue. If you have any 3.0 or 2.2.1 devices, can you see this issue? Does it make any difference if you set validatesSecureCertificate to NO? (I don't recommend you do this in shipping apps)
I guess it's possible that a bug has crept in somewhere which is causing this error to be erroneously triggered, perhaps the release of the problem ASIHTTPRequest code coincided with the 3.1 release. Are you using the latest version of ASIHTTPRequest?
It would be helpful if you could drop me details on the url(s) you're seeing this problem with - ben@allseeing-i.com.
Thanks
Ben
-
Progress tracking code feels messy and contains lots of repetition.
lhunath's fork has moved the queue progress methods into a protocol, it would be worth looking at this too.
Comments





It seems like this issue was fixed by c73fb11