2012-01-21 9 views
0

誰でもこの問題の解決策を見つけるのを手伝ってください。ダウンロードされたコンテンツはiws> 2500バイトですが、変換中にnsstringは空を返します。utf-8 type does not accept> nsurlconnectionのダウンロード中に129バイトを超える

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

staus:204しかしstrUserResponseが

+1

'dataRequest'には実際に何が含まれていますか? 'postString'に追加するときに文字列をUTF-8に変換し、それをLatin-1に変換するので、データが切り捨てられているのは驚きではありません。 – sbooth

+2

204は「内容なし」ですが、どのようにしてresponseDataを期待できますか? –

答えて

2

204 HTTPレスポンスコードは空ではコンテンツがなく、strUserResponseが必要なデータが含まれないことを次のようresponseDataは何も含まれませんを意味しません。

204リターンコードの意味:

サーバは要求を受信したが バックを送信するために情報がない、とクライアントが同じドキュメントビューに滞在する必要があります。これは、同じ時刻に の文書を変更せずにスクリプトの入力を主に許可するために、 です。

httpリターンコードを無視しないでください。

HTTPレスポンスの定義を参照してください。Status Code Definitions

また、このような何かをデバッグするために、あなたはresponseDataの値が何であるか、この場合には、ストリームをバック検証するために、デバッガとコンソールまたはのNSLogを使用することができます。