使用ASIFormDataRequest错误发布XML数据

时间:2012-12-07 08:55:41

标签: objective-c xml asiformdatarequest

NSURL *postUrl =[[NSURL alloc] initWithString:mainString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:postUrl];
[request setResponseEncoding:NSUTF8StringEncoding];

NSString *msgLength = [NSString stringWithFormat:@"%d", [xmlString length]];
[request addRequestHeader:@"Content-Length" value:msgLength];

NSString *contentType = [NSString stringWithFormat:@"application/xml"];
[request addRequestHeader:@"Content-Type" value:contentType];

// [请求addRequestHeader:@“Content-Type”值:@“application / json”]; // Test for JSON很好     [请求appendPostData:theData];     [request buildPostBody];     [请求setRequestMethod:@“POST”];

[request setDelegate:self];
[request startAsynchronous];
[request setTimeOutSeconds:20];// 测试连接的时间,默认10s
[postUrl release];

我从以下代码中获取Nothing,这也不会产生错误。

(void)requestFinished:(ASIHTTPRequest *)request{
    NSData *theData = [request responseData];
    NSString *ret = [request responseString];
    NSLog(@"ret--------------%@",ret);
}

当我使用JSON时,我得到了结果。

0 个答案:

没有答案