我是Objective c的新手,遇到了一个问题,该问题只有在我执行HTTP POST请求时才会出现。
我用我的iPhone进行HTTP请求,我希望服务器在标头中向我返回类似的内容(这是来自其他服务器的响应标头):
{
"Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
Connection = close;
"Content-Length" = 0;
"Content-Type" = "text/html";
Date = "something";
Expires = "something";
Location = "/mylocation/10"; <--- this is what i want
Pragma = "no-cache";
Server = "Apache/2.2.3 (CentOS)";
"Set-Cookie" = "something";
"X-Powered-By" = "PHP/5.3.3";
}
当我成功发帖时,它会执行所需的功能,并返回一个空响应,标题如下:
{
"Cache-Control" = "max-age=0, no-cache";
Connection = close;
"Content-Length" = 0;
"Content-Type" = "text/html";
Date = "something";
Server = "Apache/2.2.14 (Ubuntu)";
}
即使我添加了"Cache Control"="没有存储,没有缓存,必须重新验证,post-check=0,pre-check=0"之类的标题,它们也不会显示在响应标题中
我应该怎么做才能得到正确的页眉?
其他信息
我使用ASIFormDataRequest进行请求,这是我设置标题的代码:
{
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:something];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Authorization" value:@"something"];
[request addRequestHeader:@"Accept" value:@"application/json,*/*;q=0.8"];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
}
这就是我获取响应标头的方式:
{
[request startSynchronous];
NSLog(@"%@", [request responseHeaders]);
}
只有在重定向期间才会发送位置标头。当我们使用PUT方法添加资源时,新创建的URL将被添加到Location标头中,并作为响应的一部分发送。在3xx重定向期间也会发生这种情况。