开发者

iPhone and SOAP Web Services

I've been reading up on web services and SQL servers lately.

Basically, what I need is to access a SQL 2008 Server from the iPhone, so I go about creating SOAP web services as per http://www.developer.com/net/asp/article.php/10917_3767311_1/Creating-Native-Web-Services-in-SQL-Server.htm

Next, I access the data using the tutorial found here: http://icodeblog.com/2008/11/0开发者_如何学C3/iphone-programming-tutorial-intro-to-soap-web-services/

But what I also need is to send data, say a picture from the iPhone to the server using this web service. Is this possible? And if so, is there a tutorial out there which can help me?

Thank you.


This is code I use to send a file to my server using an HTTP POST command

- (NSURLRequest *)fileUploadRequestWithURL: (NSURL *)url 
                                   boundry: (NSString *)boundry 
                                      data: (NSData *)data    
{
    NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];    

    // set up the request
    [urlRequest setHTTPMethod:@"POST"];
    [urlRequest setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundry] forHTTPHeaderField:@"Content-Type"];

    // allocate memort for the data
    NSMutableData *postData = [NSMutableData dataWithCapacity:[data length] + 512];

    // set the data
    [postData appendData:[[NSString stringWithFormat:@"--%@\r\n",boundry] dataUsingEncoding:NSUTF8StringEncoding]];
    [postData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"data\"; filename=\"%@\"\r\n", [filePath lastPathComponent]] dataUsingEncoding:NSUTF8StringEncoding]];
    [postData appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [postData appendData:data];
    [postData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundry] dataUsingEncoding:NSUTF8StringEncoding]];

    // append to the request
    [urlRequest setHTTPBody:postData];

    // return the request
    return urlRequest;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜