Toggle navigation
Toggle navigation
This project
Loading...
Sign in
iOS
/
asi-http-request
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jamie Pinkham
2010-09-28 09:52:02 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d6197f9db314a1680e2c1113ee8f282413b999c8
d6197f9d
1 parent
e684fb65
added use cases in iphone sample
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
2 deletions
iPhone Sample/AuthenticationViewController.m
iPhone Sample/QueueViewController.m
iPhone Sample/SynchronousViewController.m
iPhone Sample/UploadViewController.m
iPhone Sample/AuthenticationViewController.m
View file @
d6197f9
...
...
@@ -19,6 +19,12 @@
[
self
setRequest
:[
ASIHTTPRequest
requestWithURL
:[
NSURL
URLWithString
:
@"http://allseeing-i.com/top_secret/"
]]];
[
request
setUseKeychainPersistence
:[
useKeychain
isOn
]];
[
request
setDelegate
:
self
];
[
request
setAuthenticationNeededBlock
:
^
(
ASIHTTPRequest
*
request
){
NSLog
(
@"authentication needed"
);
}];
[
request
setProxyAuthenticationNeededBlock
:
^
(
ASIHTTPRequest
*
request
){
NSLog
(
@"proxy authentication needed"
);
}];
[
request
setShouldPresentAuthenticationDialog
:[
useBuiltInDialog
isOn
]];
[
request
setDidFinishSelector
:
@selector
(
topSecretFetchComplete
:)];
[
request
setDidFailSelector
:
@selector
(
topSecretFetchFailed
:)];
...
...
iPhone Sample/QueueViewController.m
View file @
d6197f9
...
...
@@ -17,6 +17,16 @@
-
(
IBAction
)
fetchThreeImages
:(
id
)
sender
{
ASIHTTPRequestSizeBlock
sizeBlock
=
^
(
ASIHTTPRequest
*
request
,
long
long
size
){
NSDictionary
*
userInfo
=
[
request
userInfo
];
NSLog
(
@"request - %@ named = %@ download size incremented %lld"
,
request
,
[
userInfo
valueForKey
:
@"name"
],
size
);
};
ASIHTTPRequestProgressBlock
bytesBlock
=
^
(
ASIHTTPRequest
*
request
,
unsigned
long
long
size
,
unsigned
long
long
total
){
NSDictionary
*
userInfo
=
[
request
userInfo
];
NSLog
(
@"request - %@ named - %@ downloaded bytes size %llu of total: %llu"
,
request
,
[
userInfo
valueForKey
:
@"name"
],
size
,
total
);
};
[
imageView1
setImage
:
nil
];
[
imageView2
setImage
:
nil
];
[
imageView3
setImage
:
nil
];
...
...
@@ -34,18 +44,27 @@
ASIHTTPRequest
*
request
;
request
=
[
ASIHTTPRequest
requestWithURL
:[
NSURL
URLWithString
:
@"http://allseeing-i.com/ASIHTTPRequest/tests/images/small-image.jpg"
]];
[
request
setDownloadSizeIncrementedBlock
:
sizeBlock
];
[
request
setBytesReceivedBlock
:
bytesBlock
];
[
request
setDownloadDestinationPath
:[[
NSHomeDirectory
()
stringByAppendingPathComponent
:
@"Documents"
]
stringByAppendingPathComponent
:
@"1.png"
]];
[
request
setDownloadProgressDelegate
:
imageProgressIndicator1
];
[
request
setUserInfo
:[
NSDictionary
dictionaryWithObject
:
@"request1"
forKey
:
@"name"
]];
[
networkQueue
addOperation
:
request
];
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:[
NSURL
URLWithString
:
@"http://allseeing-i.com/ASIHTTPRequest/tests/images/medium-image.jpg"
]]
autorelease
];
[
request
setDownloadSizeIncrementedBlock
:
sizeBlock
];
[
request
setBytesReceivedBlock
:
bytesBlock
];
[
request
setDownloadDestinationPath
:[[
NSHomeDirectory
()
stringByAppendingPathComponent
:
@"Documents"
]
stringByAppendingPathComponent
:
@"2.png"
]];
[
request
setDownloadProgressDelegate
:
imageProgressIndicator2
];
[
request
setUserInfo
:[
NSDictionary
dictionaryWithObject
:
@"request2"
forKey
:
@"name"
]];
[
networkQueue
addOperation
:
request
];
request
=
[[[
ASIHTTPRequest
alloc
]
initWithURL
:[
NSURL
URLWithString
:
@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"
]]
autorelease
];
[
request
setDownloadSizeIncrementedBlock
:
sizeBlock
];
[
request
setBytesReceivedBlock
:
bytesBlock
];
[
request
setDownloadDestinationPath
:[[
NSHomeDirectory
()
stringByAppendingPathComponent
:
@"Documents"
]
stringByAppendingPathComponent
:
@"3.png"
]];
[
request
setDownloadProgressDelegate
:
imageProgressIndicator3
];
[
request
setUserInfo
:[
NSDictionary
dictionaryWithObject
:
@"request3"
forKey
:
@"name"
]];
[
networkQueue
addOperation
:
request
];
[
networkQueue
go
];
...
...
iPhone Sample/SynchronousViewController.m
View file @
d6197f9
...
...
@@ -19,12 +19,41 @@
{
NSURL
*
url
=
[
NSURL
URLWithString
:[
urlField
text
]];
NSMutableData
*
recievedData
=
[
NSMutableData
data
];
// Create a request
// You don't normally need to retain a synchronous request, but we need to in this case because we'll need it later if we reload the table data
[
self
setRequest
:[
ASIHTTPRequest
requestWithURL
:
url
]];
//Customise our user agent, for no real reason
[
request
addRequestHeader
:
@"User-Agent"
value
:
@"ASIHTTPRequest"
];
[
request
setStartedBlock
:
^
(
ASIHTTPRequest
*
aRequest
){
NSLog
(
@"started!"
);
}];
[
request
setHeadersReceivedBlock
:
^
(
ASIHTTPRequest
*
aRequest
){
NSLog
(
@"headers recieved"
);
}];
[
request
setBytesReceivedBlock
:
^
(
ASIHTTPRequest
*
aRequest
,
unsigned
long
long
length
,
unsigned
long
long
total
){
NSLog
(
@"bytes received:%llu of total: %llu"
,
length
,
total
);
}];
[
request
setDownloadSizeIncrementedBlock
:
^
(
ASIHTTPRequest
*
aRequest
,
long
long
length
){
NSLog
(
@"download size incremented:%lld"
,
length
);
}];
[
request
setDataReceivedBlock
:
^
(
ASIHTTPRequest
*
aRequest
,
NSData
*
data
){
[
recievedData
appendData
:
data
];
NSLog
(
@"data - %@"
,
recievedData
);
}];
[
request
setCompletionBlock
:
^
(
ASIHTTPRequest
*
aRequest
){
if
([
aRequest
error
])
{
NSLog
(
@"error from block"
);
}
else
if
([
aRequest
responseString
])
{
NSLog
(
@"finish from block"
);
}
}];
// Start the request
[
request
startSynchronous
];
...
...
iPhone Sample/UploadViewController.m
View file @
d6197f9
...
...
@@ -20,10 +20,17 @@
[
request
setPostValue
:
@"test"
forKey
:
@"value2"
];
[
request
setPostValue
:
@"test"
forKey
:
@"value3"
];
[
request
setTimeOutSeconds
:
20
];
[
request
setUploadProgressDelegate
:
progressIndicator
];
[
request
setBytesSentBlock
:
^
(
ASIHTTPRequest
*
request
,
unsigned
long
long
length
,
unsigned
long
long
total
){
NSLog
(
@"sent %llu bytes of %llu total"
,
length
,
total
);
}];
[
request
setUploadSizeIncrementedBlock
:
^
(
ASIHTTPRequest
*
request
,
long
long
length
){
NSLog
(
@"upload size incremented = %lld"
,
length
);
}];
/*[request setUploadProgressDelegate:progressIndicator];
[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[
request
setDidFinishSelector
:
@selector
(
uploadFinished
:)];
[request setDidFinishSelector:@selector(uploadFinished:)];
*/
//Create a 256KB file
NSData
*
data
=
[[[
NSMutableData
alloc
]
initWithLength
:
256
*
1024
]
autorelease
];
...
...
Please
register
or
login
to post a comment