Objective c 使用AFN网络使用web服务发送音频

Objective c 使用AFN网络使用web服务发送音频,objective-c,web-services,afnetworking,nsdata,Objective C,Web Services,Afnetworking,Nsdata,我有一个音频,我需要使用Web服务和其他输入一起发送。在做了一些搜索之后,我明白我不能使用XML SOAP消息发送nsdata,所以我下载了AFHTTPRequest类并在internet上进行了示例,但它不起作用 这是我正在使用的web服务: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=

我有一个音频,我需要使用Web服务和其他输入一起发送。在做了一些搜索之后,我明白我不能使用XML SOAP消息发送nsdata,所以我下载了AFHTTPRequest类并在internet上进行了示例,但它不起作用

这是我正在使用的web服务:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <addlocation2 xmlns="http://tempuri.org/">
      <userid>int</userid>
      <name>string</name>
      <voicemsg>base64Binary</voicemsg>
    </addlocation2>
  </soap:Body>
</soap:Envelope>

您不需要使用AFHTTPRequest类。您的需求只是通过网络发送Base64二进制数据,您的web服务会这样说。
请点击下面的链接,这将很有帮助

谢谢你的提示,我正在寻找一种立即发送数据的方法,因为当我以字符串类型发送数据时,它非常庞大,占用了数据库中的大量空间,但如果我以数据形式发送数据,数据库会自动将其转换为字节,并以智能方式保存,因此它不会占用内存中的大量空间,并且易于检索。
   NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"m4a"];

NSData *audio = [NSData dataWithContentsOfFile:filePath];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

NSString *URLString = @"http://host.com/Websr/Service.asmx?op=addlocation2";//[WebService getAudioURL];
NSDictionary *parameters = @{@"userid": @2,
                             @"name": @"usertest",
                             };

manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"audio/m4a", nil];
[manager POST:URLString parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

    if (audio) {
        [formData appendPartWithFileData:audio name:@"voicemsg" fileName:[NSString stringWithFormat:@"test.m4a"] mimeType:@"audio/m4a"];
    }
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Success %@", responseObject);
    NSLog(@"operation %@", operation.responseString);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Failure" message:@"Sending Failure" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    NSLog(@"Failure %@, %@", error, operation.responseString);
}];

[self dismissViewControllerAnimated:NO completion:nil];
- (BOOL)validateResponse:(NSHTTPURLResponse *)response
                data:(NSData *)data
               error:(NSError *)error
{
BOOL responseIsValid = YES;
NSError *validationError = nil;

if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) {
    if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]]) {
        NSLog(@"[response URL] %@", [response URL]);
         if ([data length] > 0 && [response URL]) {
                ...}