Wednesday, January 8, 2014

iPhone transfer files to the server

I think the iPhone client to upload files to the server.
web service is the axis (soap), the corresponding code:
 
public class FileService {
public String upload (DataHandler handler, String fileName) {
A series of operations
/ / save file}
}

Fragment corresponding wsdl:
 









On the client, simply type parameter passing is no problem. but because with apachesoap: DataHandler receive attachments (documents), there has not found in objc corresponding data type .
objc code: (from google)
 
NSString * soapMessage = [NSString stringWithFormat:
@ " \ N"
" "
" \ N"
""
"% @ "
"% @ "
""
"
\ n"
"", @ "aaaadd", @ "aa.txt"];
NSLog (@ "String call webserivce is:% @", soapMessage);
Path / / send the request to the
NSString * msgLength = [NSString stringWithFormat: @ "% d", [soapMessage length]];
NSURL * url = [NSURL URLWithString: @ "http://10.188.96.27:8080/AudioService/services/FileService?wsdl"];
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL: url];

/ / The following request for information must be added before the property is a four sentences,
[UrlRequest addValue: @ "text / xml; charset = utf-8" forHTTPHeaderField: @ "Content-Type"];
[UrlRequest addValue: @ "http://10.188.96.27:8080/AudioService/services/FileService?wsdl" forHTTPHeaderField: @ "SOAPAction"];
[UrlRequest addValue: msgLength forHTTPHeaderField: @ "Content-Length"];
[UrlRequest setHTTPMethod: @ "POST"];
[UrlRequest setHTTPBody: [soapMessage dataUsingEncoding: NSUTF8StringEncoding]];

/ / Request
NSURLConnection * theConnection = [[NSURLConnection alloc] initWithRequest: urlRequest delegate: self];
theConnection = nil;

Ask you, usually in ios processing file uploads is how to do it? I am new to ios, please advise :)
Reply:
Try to use a third-party library ASIHTTPRequest or AFNetworking
Reply:
Anzhe few days just to get this thing probably you can look
http://www.999dh.net/article/iphone_ios_art/30.html
http://www.999dh.net/article/iphone_ios_art/29.html
This article 2 are two different methods for data transmission

No comments:

Post a Comment