サーバーにASP.NETMVCがあります。Iphoneは、Http要求をASP.NETMVCコントローラーに送信しています。これがiPhoneコードです。
-(void)addNSData:(NSData*)datapart inData:(NSMutableData*)POSTBody forkey:(NSString*)key
{
[POSTBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
[POSTBody appendData:[[NSString stringWithFormat:@"%@", datapart] dataUsingEncoding:NSUTF8StringEncoding]];
[POSTBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", POSTBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
}
{
NSMutableURLRequest *request = nil;
request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://XXX/XXX/publish"]];
NSString *jsonFilePath = [[SharedData shareData].pageDataFolderPath stringByAppendingPathComponent:@"page_json.json"];
[ request setHTTPMethod: @"POST" ];
[request addValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", POSTBoundary] forHTTPHeaderField:@"Content-Type"];
[request addValue:@".ASPXAUTH=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" forHTTPHeaderField:@"Cookie"];
// Add HTTP Body
NSMutableData *POSTBody = [NSMutableData data];
[POSTBody appendData:[[NSString stringWithFormat:@"--%@\r\n",POSTBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[self addNSData:[NSData dataWithContentsOfFile:localZipPath] inData:POSTBody forkey:@"zipFile"];
[self addNSData:[NSData dataWithContentsOfFile:jsonFilePath] inData:POSTBody forkey:@"contents"];
NSString *v = page.mo_page.version;
[self addNSData:[v dataUsingEncoding:NSUTF8StringEncoding] inData:POSTBody forkey:@"version"];
[self addNSData:[@"true" dataUsingEncoding:NSUTF8StringEncoding] inData:POSTBody forkey:@"isActive"];
[self addNSData:[page.mo_page.pageid dataUsingEncoding:NSUTF8StringEncoding] inData:POSTBody forkey:@"directory"];
// Add the closing -- to the POST Form
[POSTBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", POSTBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
// Add the body to the myMedRequest & return
[request setHTTPBody:POSTBody];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(error)
{
NSLog(@"Error if any:%@",error.localizedDescription);
}
else {
NSLog(@"Response : %@",[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
}
[[NSFileManager defaultManager] removeItemAtPath:localZipPath error:nil];
localZipPath = nil;
}
この形式のデータを取得するASP.NETMVCサーバー(例:
Request.Form["Directory"]= "<32383862 33363339 36393538 34653463 62643862 35376561 66653135 35313764>"