问题描述:

Currently our application is using ASIFormDataRequest to post data on server.

I was using

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlWeb];

[request setShouldPresentAuthenticationDialog:NO];

[request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"];

[request setRequestMethod:@"POST"];

[request addRequestHeader:@"Content-Type" value:@"text/xml; charset=utf-8"];

[request addRequestHeader:@"SOAPAction" value:@"http://something"];

[request setUsername:@"ABC"];

[request setPassword:@"XYZ"];

[request setDomain:@"LMN"];

[request appendPostData:[strSoapEnvl dataUsingEncoding:NSUTF8StringEncoding] ];

[request setDelegate:self];

[request setTimeOutSeconds:60];

[request setNumberOfTimesToRetryOnTimeout:2];

[request startAsynchronous];

BUT ASIHTTPRequest is not supporting ARC. So I have decided to use MKNetworkKIt as replacement. But I am not getting any sample code to do the same.

I have seen downloaded code from github of Mugunth Kumar but there they used NSMutableDictionary object as parameter in MKNetworkOperation.

网友答案:

For SOAP, you should use something like this.

[op setCustomPostDataEncodingHandler:^NSString *(NSDictionary *postDataDict) {

    DDXMLDocument *doc = [[DDXMLDocument alloc] initWithXMLString:[rootElement XMLString] 
                                                      options:0 
                                                        error:nil];
    return [doc XMLString];

} forType:@"text/xml"];

NSDictioanry is for JSON, or URL or x-plist encoding which are infact the most common encoding types.

相关阅读:
Top