[英]iOS 7 - header HTTP header request?
我对iOS 7并不是很熟悉,我正在尝试构建一个需要设置值并将HTTP请求标头发送到我的服务器的应用程序。 但是,看来我的服务器确实收到了我发送的值,这是我从FacebookSDK获得的令牌(我已经在使用FacebookSDK登录,现在我已经掌握了令牌),因为我收到了以下通知:服务器没有将其视为HTTPReques标头。 这是我的代码:
- (void)postToken
{
// Get the token from Facebook
NSString *token = FBSession.activeSession.accessTokenData.accessToken;
// Create the server name
NSMutableString *server = [[NSMutableString alloc] init];
[server appendString:@"*My server website here*"];
// URL Request and initialization
NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:server]];
[postRequest setValue:token forHTTPHeaderField:@"Token"];
// Set the request's content type
[postRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[postRequest setValue:token forHTTPHeaderField:@"Token"];
// Designate the request a POST request and specify its body data
[postRequest setHTTPMethod:@"POST"];
// The delegate provides receives notification
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:mutableReq delegate:self];
self.connection = connection;
[self.connection scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[self.connection start];
if (self.connection) // if connect successfully
{
NSLog(@"Connection Success!");
NSURL *url = [NSURL URLWithString:server]; // Initialize url
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; // Initialize request
NSURLResponse *server_response = [[NSURLResponse alloc] init]; // Initialize response
self.receivedData = [[NSMutableData alloc] init];
[self.receivedData appendData:[NSURLConnection sendSynchronousRequest:request returningResponse:&server_response error:nil]]; // Receive data synchronously
[self connectionDidFinishLoading:self.connection];
}
else
NSLog(@"Connection Failed!");
}
输出为“连接成功!” 并且输出包含我的令牌(因此我不想在此处发布)以及服务器发出的消息,告诉我未提供令牌,这意味着它可以与服务器通信,但是服务器未将令牌识别为标头HTTP请求。 有人可以帮我吗? 提前致谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.