1
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];

// [request addRequestHeader:@"Content-Type" value:@"application/json"];//测试JSON是好的[request appendPostData:theData]; [请求 buildPostBody]; [请求 setRequestMethod:@"POST"];

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

我从以下代码中没有得到任何东西,这也不会产生错误。

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

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

4

0 回答 0