发送不正确的数据我有正确设定请求的HTTPBody的问题。我使用OAuth与我们的API服务器进行通信,唯一的区别是,我需要的,不是头(使用OauthConsumer.framework - http://code.google.com/p/oauthconsumer/wiki/UsingOAuthConsumer)通过身体发送数据。setHTTPBody在NSMUtableURLRequest
这是我的代码:
NSString *oauthHeader = [NSString stringWithFormat:@"OAuth realm=\"%@\", oauth_consumer_key=\"%@\", %@oauth_signature_method=\"%@\", oauth_signature=\"%@\", oauth_timestamp=\"%@\", oauth_nonce=\"%@\", oauth_version=\"1.0\"%@",
[realm URLEncodedString],
[consumer.key URLEncodedString],
oauthToken,
[[signatureProvider name] URLEncodedString],
[signature URLEncodedString],
timestamp,
nonce,
extraParameters];
//[self setValue:oauthHeader forHTTPHeaderField:@"Authorization"];
NSLog(@"%@", oauthHeader);
[self setHTTPBody:[oauthHeader dataUsingEncoding:NSASCIIStringEncoding]];
这就是NSLog的输出。
OAuth的境界= “”,oauth_consumer_key = “键”,oauth_signature_method = “HMAC-SHA1”,oauth_signature = “HT2UwJoW4dSNh1gXkAzQThLp0Sk%3D”,oauth_timestamp = “1340789377”,oauth_nonce =“3BDF0A1A-4FB0-40EF-95EA-5CB8B0FD07C1 ” oauth_version =‘1.0’
而这正是服务器读取,为什么数组是错误的?这不是服务器端错误,我们的C#客户端没有任何问题。
array(1) { ["OAuth_realm"]=> string(215) """, oauth_consumer_key="key", oauth_signature_method="HMAC-SHA1", oauth_signature="HT2UwJoW4dSNh1gXkAzQThLp0Sk=", oauth_timestamp="1340789377", oauth_nonce="3BDF0A1A-4FB0-40EF-95EA-5CB8B0FD07C1", oauth_version="1.0"" }
这是服务器从Windows客户端接收到的内容:
– Thunder