2010-07-05 112 views
-1

最近我一直在閱讀Web服務和SQL服務器。iPhone和SOAP Web服務

基本上,我需要的是從iPhone訪問SQL 2008服務器,所以我去按http://www.developer.com/net/asp/article.php/10917_3767311_1/Creating-Native-Web-Services-in-SQL-Server.htm

下一頁創建SOAP Web服務,我訪問使用教程這裏找到的數據:http://icodeblog.com/2008/11/03/iphone-programming-tutorial-intro-to-soap-web-services/

但我還需要發送數據,例如從iPhone到使用此Web服務的服務器的圖片。這可能嗎?如果是這樣,那裏有教程可以幫助我嗎?

謝謝。

+0

http://www.iphonedevsdk.com/forum/iphone-sdk-development/2841-resolved-how -call-soap-service.html – slf 2010-07-05 01:24:57

+0

謝謝slf,但似乎沒有辦法發送數據。我只看到如何從服務器上提取數據的方法。 – 2010-07-05 01:48:44

回答

0

這是代碼,我用它來使用HTTP POST命令將文件發送到我的服務器

- (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; 
}