0
任何人都可以幫助我找到解決此問題的解決方案嗎?下載的內容iws> 2500字節,但轉換後的nsstring返回空。utf-8類型在下載時不接受> 129字節nsurlconnection
NSMutableString *postString = [NSMutableString string];
// NSMutableString *postString = [[NSMutableString alloc] init];
[postString appendFormat:@"username=%@",[strUsrName dataUsingEncoding:NSUTF8StringEncoding]];
[postString appendFormat:@"&password=%@",[strPasswrd dataUsingEncoding:NSUTF8StringEncoding]];
[postString appendFormat:@"&client_assertion_type=%@",[@"JWT"dataUsingEncoding:NSUTF8StringEncoding]];
[postString appendFormat:@"&client_assertion=%@",[strAppTknContent dataUsingEncoding:NSUTF8StringEncoding]];
[postString appendFormat:@"&spEntityID=%@",[@"http://localhost:8080/opensso"dataUsingEncoding:NSUTF8StringEncoding]] ;
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] initWithURL:nsurl];
NSData* dataRequest = [postString dataUsingEncoding: NSISOLatin1StringEncoding ];
// NSData* dataRequest = [NSData dataWithBytes:strRequest];
[theRequest setHTTPMethod: @"POST"];
[theRequest setHTTPBody: dataRequest];
[theRequest setURL:nsurl];
//// set headers
NSString *contentType = [NSString stringWithFormat:@"text/plain"];
[theRequest setValue:contentType forHTTPHeaderField:@"Content-Type"];
NSString *acceptType = [NSString stringWithFormat:@"application/json"];
[theRequest setValue:acceptType forHTTPHeaderField:@"accept"];
[theRequest setTimeoutInterval:3.0];
[theRequest setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
NSData *responseData =[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSString *strUserResponse =[[NSString alloc]initWithData:responseData encoding:NSISOLatin1StringEncoding];
int status =[response statusCode ] ;
居留制:204,但strUserResponse是空
dataRequest'實際包含什麼?將字符串附加到「postString」後將字符串轉換爲UTF-8,然後將其轉換爲Latin-1,所以我並不驚訝數據被截斷。 – sbooth
204是「沒有內容」,你怎麼能期待一個responseData? –