HTTP请求标头

YaBCK

好的。我一直在使用原始HTTP请求,发现可以将原始HTTP响应发布到NSLog中,并且几乎将原始HTTP请求破解到NSLog中。我现在有点卡住了。

代码示例

   NSString *CurrentWebURL = webView.request.URL.absoluteString;
   NSURLSession *session= [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
   [[session dataTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:CurrentWebURL]] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
   NSDictionary *requestdictionary = [request allHTTPHeaderFields];
   NSLog(@"----shouldStartLoadWithRequest Raw HTTPRequest Start ----");
   for (NSString *Object in [requestdictionary allKeys]) {
         NSLog(@"%@: %@",Object, [requestdictionary objectForKey:Object]);
   }
   NSLog(@"----shouldStartLoadWithRequest Raw HTTPRequest Finish ----"] withlevel:SPECIAL_LOG);

   }]resume];

原始请求:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (iPad; CPU OS 7_0_6 like Mac OS X)  AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11B651

它应该显示“ Get:URL”,“ HOST”,“ Connection:Keep-alive”,“ Accept-Encoding”,“ Accept”,“ Cookie”,“ Connection”,“ Accept-Language”和“ User-代理”。

我的问题是为什么只显示“接受”和“用户代理”?

提出要求:

  NSURL *url = [NSURL URLWithString:PortalURL];

  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
  [request setHTTPShouldHandleCookies:YES];
  [request setHTTPMethod: @"GET"];

Fiddler请求跟踪(无任何自定义标头):

  GET http://URL/ HTTP/1.1
  Host: Host.co.uk
  Connection: keep-alive
  Accept-Encoding: gzip, deflate
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Cookie: IsosecCookie=Chris%20Beckett
  Connection: keep-alive
  Accept-Language: en-gb
  User-Agent: Mozilla/5.0 (iPad; CPU OS 7_0_6 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11B651

在NSLog中记录请求标头:

  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  User-Agent: Mozilla/5.0 (iPad; CPU OS 7_0_6 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11B651
YaBCK

我得出的结论是,无法使用NSURLRequest在iOS中获得原始HTTP请求,您只能获得“ Accept”和“ User-Agent”。

但是我已经解决了,要获取原始HTTP请求,我已经使用php来获取标头。我知道这不是最好的解决方案,但是它可以工作,而且能够记录此信息而不必继续通过Fiddler或Charles代理之类的代理,这是很棒的。

iOS代码

NSURL *PHPURL = ([NSURL URLWithString:[NSString stringWithFormat:@"http://office.isosec.co.uk/Audit/testRequest.php?"]]);
request = [[NSMutableURLRequest alloc] initWithURL:PHPURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
[request setHTTPMethod: @"GET"];
[request setHTTPShouldHandleCookies:YES];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];

PHPResponse = [NSMutableData data];

if( connection == nil ) {
    [ViewController remoteLog:[NSString stringWithFormat:@"PHPRequest Connection Failed"] withlevel:SPECIAL_LOG];
} else {
    [ViewController remoteLog:[NSString stringWithFormat:@"PHPRequest Connection Started"] withlevel:SPECIAL_LOG];
    [connection scheduleInRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];
    [connection start];
}

PHP代码

foreach (getallheaders() as $name => $value) {
    echo "$name: $value,";
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

预览请求的标准HTTP请求标头

来自分类Dev

匹配缺少某些标头的HTTP请求

来自分类Dev

创建HTTP GET标头请求

来自分类Dev

使用AngularJS发送HTTP标头请求

来自分类Dev

HTTP / 2请求标头压缩

来自分类Dev

从JavaScript设置常规HTTP请求标头

来自分类Dev

Akka-http非法请求标头

来自分类Dev

HTTP请求标头和缓存

来自分类Dev

使用标头“ origin”验证HTTP请求

来自分类Dev

无法从请求获取HTTP标头

来自分类Dev

使用AngularJS发送HTTP标头请求

来自分类Dev

创建HTTP GET标头请求

来自分类Dev

AngularJs HTTP请求标头未更改

来自分类Dev

Android中的HTTP请求标头问题

来自分类Dev

HTTP / 2请求标头压缩

来自分类Dev

在 Http 请求中设置标头

来自分类Dev

AngularJS如何在Http请求中包含标头

来自分类Dev

无法将http请求标头写入perl中的文件

来自分类Dev

spnego实现问题-解析HTTP请求标头时出错

来自分类Dev

Android:Volley HTTP请求自定义标头

来自分类Dev

使用Python请求模块获取HTTP响应标头

来自分类Dev

从HTTPie的请求中删除默认的HTTP标头

来自分类Dev

Tomcat 7.0.43“ INFO:解析HTTP请求标头时出错”

来自分类Dev

如何从Rocket中的请求检索HTTP标头?

来自分类Dev

Android:Volley HTTP请求自定义标头

来自分类Dev

播放框架,设置HTTP POST请求标头

来自分类Dev

ngx_lua如何删除http请求标头

来自分类Dev

客户端请求的ReastEasy Http标头

来自分类Dev

在angular dart上设置全局Http请求标头