2011-07-31 11 views
0

이 방법이 있습니다.NSDictionary. NSDictionary 개체를 만드는 방법

[self postRequestWithURL: (NSString *) postArgs:(NSDictionary *) headerArgs: (NSDictionary *) ]; 

이 방법을 올바르게 호출하려면 어떻게해야합니까?

URL은 : http://www.google.com/reader/api/0/edit-tag?

포스트 인수는 다음과 같습니다 "a=user/-/state/com.google/read&ac=edit-tags&s=feed/%@&i=%@&T=%@", entry.link, entry.identifier, tokenString

와 헤더는 다음과 같습니다

NSString *authHeader = [NSString stringWithFormat:@"GoogleLogin %@", authString]; 
[thttpReq addValue:authHeader forHTTPHeaderField:@"Authorization"]; 

[thttpReq addValue:@"Content-Type" forHTTPHeaderField:@"application/x-www-form-urlencoded"]; 

NSDictionary에서 postArgs 및 HeaderArgs를 삽입하는 데 도움이 sompne 수 있습니까? 감사합니다 파올

답변

5

는 다음과 같이하십시오 : dictionaryWithObjectsAndKeys: 다음의 목록은 쉼표로 분리 된 객체와 키의 교대를 포함

NSDictionary *postArgs = [NSDictionary dictionaryWithObjectsAndKeys: 
          @"user/-/state/com.google/read", @"a", 
          @"edit-tags", @"ac", 
          [NSString stringWithFormat: @"feed/%@", entry.link], @"s", 
          [NSString stringWithFormat: @"%@", entry.identifier], @"i", 
          [NSString stringWithFormat: @"%@", tokenString], @"T", 
          nil]; 

NSDictionary *headerArgs = [NSDictionary dictionaryWithObjectsAndKeys: 
          [NSString stringWithFormat: @"GoogleLogin %@", authString], @"Authorization", 
          @"application/x-www-form-urlencoded", @"Content-Type" 
          nil]; 

[self postRequestWithURL: @"http://www.google.com/reader/api/0/edit-tag" 
       postArgs: postArgs 
       headerArgs: headerArgs]; 

참고, 최종 nil 다음을, 위의 예와 같습니다.

FWIW의 사전은 자동으로 등록되므로 명시 적으로 해제 할 필요가 없습니다.

2

NSDictionary 또는 NSMutableDictionary 설명서를 읽어보십시오. 여기 당신이 그것을 할 거라고 방법은 다음과 같습니다

NSString * feed = [NSString stringWithFormat: @"feed/%@&i=%@&T=%@", entry.link, entry.identifier, tokenString]; 
NSDictionary * parameters = [[NSDictionary alloc] initWithObjectsAndKeys: @"a", @"user/-/state/com.google/read", @"ac", @"edit-tags", @"s", feed, nil]; 
+0

감사합니다. 제게 headerArgs 단계를 보여주십시오. –

+0

내 대답보기. 제 생각에는'Content-Type'이 핵심이고'application/x-www-form-urlencoded'는 그 값이고 다른 방법은 아닙니다. –