Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c AFNetworking上载进程发送SOAP NSData_Objective C_Ios_Afnetworking_Nsmutableurlrequest - Fatal编程技术网

Objective c AFNetworking上载进程发送SOAP NSData

Objective c AFNetworking上载进程发送SOAP NSData,objective-c,ios,afnetworking,nsmutableurlrequest,Objective C,Ios,Afnetworking,Nsmutableurlrequest,我正在使用AFNetworking,希望将NSData对象上载到我的服务器。我试图上传到我们的SOAP服务器,所以我有XML,我已经转换成了一个NSData对象。由于某些原因,以下操作不起作用: // Back to NSData NSData *convertedFile = [xml dataUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL URLWithString:siteConfiguration.soa

我正在使用
AFNetworking
,希望将
NSData
对象上载到我的服务器。我试图上传到我们的SOAP服务器,所以我有XML,我已经转换成了一个
NSData
对象。由于某些原因,以下操作不起作用:

// Back to NSData
    NSData *convertedFile = [xml dataUsingEncoding:NSUTF8StringEncoding];

    NSURL *url = [NSURL URLWithString:siteConfiguration.soapURL];
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
    NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
        [formData appendPartWithFormData:convertedFile name:assetCreation.name];
    }];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {

        // Progress
        float totalProgress = (float)totalBytesWritten/(float)totalBytesExpectedToWrite;
        progress(totalProgress, totalBytesWritten, totalBytesExpectedToWrite);
        if (totalBytesExpectedToWrite == totalBytesWritten) {

            completion();

        }
    }];
    [operation start];

似乎我的服务器真的想用我的
NSData
对象发送
HTTPBody
。是否可以对AFNetworking进程回调执行相同的操作?

好的,我已经让它工作了。看来我做错了:

// Setup the connection
    NSString *wsdlURL = [NSString stringWithFormat:@"%@?WSDL", siteConfiguration.soapURL];
    NSURL *serviceUrl = [NSURL URLWithString:wsdlURL];
    NSMutableURLRequest *serviceRequest = [NSMutableURLRequest requestWithURL:serviceUrl];
    [serviceRequest setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
    [serviceRequest setHTTPMethod:@"POST"];
    [serviceRequest setHTTPBody:[xml dataUsingEncoding:NSUTF8StringEncoding]];

    // Operation
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:serviceRequest];
    [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {

        // Progress
        float totalProgress = (float)totalBytesWritten/(float)totalBytesExpectedToWrite;
        progress(totalProgress, totalBytesWritten, totalBytesExpectedToWrite);

    }];
    [operation  setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success");
        MatrixAsset *asset = [[MatrixAsset alloc] init];
        completion(asset);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error: %@", error.localizedDescription);
        NSLog(@"error: %@", error.localizedFailureReason);
    }];
    [operation start];

您需要SOAPAction才能继续:

[serviceRequest setValue:@"SOAP_ACTION_URL" forHTTPHeaderField:@"SOAPAction"];

您是否尝试过
[formData appendPartWithFileData:convertedFile name:assetCreation.name]
而不是
[formData appendPartWithFormData:convertedFile name:assetCreation.name]?我还将
mimeType:
设置为
text/xml
至少在最新版本的AFNetworking中没有名为[formData appendPartWithFileData:convertedFile name:assetCreation.name]的方法。我想我需要以表单的形式发送它,因为它是发送到我们的SOAP服务器的,并且还有其他字段数据正在发送。将内容类型设置为text/xml没有帮助。我使用了:[请求setValue:@“text/xml”forHTTPHeaderField:@“Content type”];它停止了进程回调的工作。
[serviceRequest setValue:@"SOAP_ACTION_URL" forHTTPHeaderField:@"SOAPAction"];