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

次のコードから Nothing を取得しますが、これもエラーを生成しません。

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

JSON を使用すると、結果が得られます。

4

0 に答える 0