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
Maarten Billemont
2009-09-27 16:19:05 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
Ben Copsey
2009-10-02 20:24:31 +0800
Commit
e5a4149dd55ae340d283008de1999e778f404059
e5a4149d
1 parent
0a9d8698
Proper encoding + charset.
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
Classes/ASIFormDataRequest.h
Classes/ASIFormDataRequest.m
Classes/ASIFormDataRequest.h
View file @
e5a4149
...
...
@@ -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
...
...
Classes/ASIFormDataRequest.m
View file @
e5a4149
...
...
@@ -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
...
...
@@ -126,7 +137,7 @@
// Set your own boundary string only if really obsessive. We don't bother to check if post data contains the boundary, since it's pretty unlikely that it does.
NSString
*
stringBoundary
=
@"0xKhTmLbOuNdArY"
;
[
self
addRequestHeader
:
@"Content-Type"
value
:[
NSString
stringWithFormat
:
@"multipart/form-data; boundary=%@"
,
stringBoundary
]];
[
self
addRequestHeader
:
@"Content-Type"
value
:[
NSString
stringWithFormat
:
@"multipart/form-data;
charset=UTF-8;
boundary=%@"
,
stringBoundary
]];
[
self
appendPostData
:[[
NSString
stringWithFormat
:
@"--%@
\r\n
"
,
stringBoundary
]
dataUsingEncoding
:
NSUTF8StringEncoding
]];
...
...
@@ -154,7 +165,7 @@
NSString
*
fileName
=
[
fileInfo
objectForKey
:
@"fileName"
];
[
self
appendPostData
:[[
NSString
stringWithFormat
:
@"Content-Disposition: form-data; name=
\"
%@
\"
; filename=
\"
%@
\"\r\n
"
,
key
,
fileName
]
dataUsingEncoding
:
NSUTF8StringEncoding
]];
[
self
appendPostData
:[[
NSString
stringWithFormat
:
@"Content-Type: %@
\r\n\r\n
"
,
contentType
]
dataUsingEncoding
:
NSUTF8StringEncoding
]];
[
self
appendPostData
:[[
NSString
stringWithFormat
:
@"Content-Type: %@
; charset=UTF-8
\r\n\r\n
"
,
contentType
]
dataUsingEncoding
:
NSUTF8StringEncoding
]];
if
([
file
isKindOfClass
:[
NSString
class
]])
{
[
self
appendPostDataFromFile
:
file
];
...
...
@@ -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
++
;
}
...
...
Please
register
or
login
to post a comment